Object-Oriented Java

Classes: Instance Variables

When we create a new class, we probably have specific details that we want the class to include. We save those specific details into instance variables.

Here is an instance variable in the Car class that describes a detail that we might want to associate with a car:

class Car {

    //Using instance variables to model our Car class after a real-life car
    int modelYear;

    public Car() {


In the example above, we created the instance variable named modelYear. Instance variables model real-world car attributes, such as the model year of a car. Finally, the instance variable is represented by the int data type.

Community Forums
Get help and ask questions in the Codecademy Forums
Report a Bug
If you see a bug or any other issue with this page, please report it here.