A static member belongs to the class itself and is shared across all objects of that class. A non-static member, also called an instance member, belongs to a particular object, so each object has its own instance variables and can call instance methods.
How the distinction works
A class defines the attributes and behaviours that its objects can have. When an object is created through instantiation, memory is allocated for that object's instance variables. By contrast, only one copy of a static variable normally exists, regardless of how many objects are created.
Consider a Student class:
class Student {
static int studentCount = 0;
String name;
Student(String newName) {
name = newName;
studentCount++;
}
static int getStudentCount() {
return studentCount;
}
String getName() {
return name;
}
}
If objects studentA and studentB are created, each has a separate name, but both share studentCount. After both are instantiated, Student.getStudentCount() returns 2.
| Member type | Ownership and access | Typical purpose |
|---|---|---|
| Static variable | One class-level value shared by all instances | Counting objects or storing a shared setting |
| Instance variable | A separate value for each object | Storing an object's individual state |
| Static method | Called through the class; cannot directly use instance members without an object reference | Operations involving class-level data |
| Instance method | Called on an object; can access that object's instance members and static members | Reading or changing an object's state |
A common misconception is that every object receives its own copy of a static variable. This is incorrect: changing the static value through one access path changes the single shared class-level value observed by all instances.
IB exam technique
For a distinguish question in B3.1, identify ownership, number of copies, and method access. Support the distinction with a short example: name is unique to each Student, while studentCount is shared by the entire class.