The big idea: A non-static (instance) variable belongs to each object — every object has its own copy.
A static (class) variable belongs to the class itself — there is exactly one copy, however many objects exist.
Step to 'Static': one shared count, and three objects each with their own title.
Interactive diagram
Explore the labelled diagram, charts and maps for this topic in full study mode.
Free preview
This is the free notes preview
You're reading the free notes. Aimnova Pro unlocks the full study experience — and you can try it with your first topic free to keep:
- FlashcardsLock in vocabulary and key terms with spaced repetition.
- Practice questionsAnswer exam-style questions and get instant AI marking.
- Mock exams & past-paper vaultSit full mocks and see exactly how examiners award marks.
- Personalised study planA daily plan built around your exam date and weak areas.
class Book:
count = 0 # STATIC — one copy, for the class
def __init__(self, title):
self.title = title # INSTANCE — one per object
Book.count = Book.count + 1
b1 = Book("Dune")
b2 = Book("Emma")
print(b1.title, b2.title) # Dune Emma — separate values
print(Book.count) # 2 — one shared counterclass Book {
static int count = 0; // STATIC — one copy, for the class
String title; // INSTANCE — one per object
Book(String title) {
this.title = title;
Book.count = Book.count + 1;
}
}
Book b1 = new Book("Dune");
Book b2 = new Book("Emma");
System.out.println(b1.title + " " + b2.title); // Dune Emma — separate values
System.out.println(Book.count); // 2 — one shared counterInstance (non-static)
- One copy per object
- Reached through the object: b1.title
- Holds what makes this object different from the others
- Created when the object is, destroyed with it
- The default choice
Static (class)
- One copy for the whole class
- Reached through the class: Book.count
- Holds what is true of all objects, or counts them
- Exists even when no objects have been created
- Use only when the value genuinely belongs to the class
A counter must be static: "How many Books have been created?" cannot be an instance variable — each object would hold its own count of 1.
The answer belongs to the class, because it is about the class, not about any one book.
Study smarter, not longer
Most students waste 40% of study time on topics they already know. Our AI tracks your progress and optimizes every minute.
An instance method uses the object
borrow() needs to know which book, so it uses the object's own data — in Python it receives self.
It cannot be called without an object, because there would be nothing for self to refer to.
A static method does not
It belongs to the class but uses no object's data — so it can be called as Book.howMany() with no object at all.
That is the test: does it need an individual object's values?
Static cannot reach instance data
There is no object to reach it on. A static method asking for an instance field has no idea which object is meant, so it is an error.
Instance methods can use both, since they have an object and the class is always available.
When to use each
Instance for anything about one particular thing. Static for counters, shared settings, and helpers that belong to the class but need no object.
In doubt, choose instance: sharing one value between every object is a decision, not a default.
Shared means shared: Changing a static variable changes it for every object at once, including ones created later.
That is the point when it is a counter — and a source of surprising bugs when it was meant to be per-object.
How this is tested — you must justify each choice from whether the value belongs to one object or to all. It comes up two ways:
Paper 2 — working with code
- Distinguish static from non-static, 3-5 marks
- Choose which a stated variable should be
- Say why a static method cannot use instance data
Paper 2 — the algorithmic-thinking question
- Reason about shared values with no code shown
- Explain the effect of changing a class variable
The classic trap: Making something static because it feels like a shared setting. Ask: would every object have the same value, always? If not, it must be an instance variable.
A BankAccount class holds an account balance and the bank's current interest rate, and must count how many accounts exist. Decide static or non-static for each, with reasons.
Model answer plan
See the answer broken into clear points, with guidance on how each point earns marks.