AP® Computer Science A glossary

Instance variable

Also called: field

Course: AP® Computer Science A Shows up in: Unit 3: Class Creation

An attribute declared in a class outside any method or constructor, whose value is unique to each object of the class.

Appears in the course and exam description (CED): 3.1.A.33.3.A.43.3.A.53.4.A.1

Instance variables define an object’s state. Each object has its own copy, so changing one object’s value does not change another’s. They are usually private, given initial values in the constructor, and default to 0, 0.0, false or null.

public class Plant
{
    private String name;   // instance variable
    private int height;    // instance variable

    public Plant(String n, int h)
    {
        name = n;
        height = h;
    }
}
Learn it properly, with a checkpoint 3.3 Anatomy of a Class

Related terms

Was this page helpful?

No names are ever shown, and every public comment is checked by us first. Please do not include personal details. To get a reply, email [email protected].

↑ Top

Enlarged view of the selected figure