Practice Flashcards
Flip to reveal answersWhat is the difference between a static and a non-static variable?
Track your progress — Sign up free to save your progress and get smart review reminders based on spaced repetition.
All 5 Flashcards — Static vs non-static
Sign up free to track progress and get spaced-repetition review schedules.
Question
What is the difference between a static and a non-static variable?
Answer
A non-static (instance) variable has one copy per object, holding what makes that object different. A static (class) variable has exactly one copy belonging to the class itself, shared by every object.
Question
Why must a counter of objects created be static?
Answer
Because it is a fact about the class, not about any one object. As an instance variable, every object would hold its own count of 1 rather than a shared running total.
Question
What is the difference between a static and an instance method?
Answer
An instance method uses the object's own data and cannot be called without an object. A static method belongs to the class, uses no object's data, and can be called as Book.count() with no object at all.
Question
Why can a static method not use instance variables?
Answer
It can be called with no object in existence, so there is nothing for self to refer to — no way to know which object's data was meant.
Question
What test decides between static and instance?
Answer
Would every object have the same value, always? Yes means static; no means it must be an instance variable. In doubt, choose instance — sharing one value is a decision, not a default.
Read the notes
Full study notes for Static vs non-static
Topic 7.1 hub
OOP: a single class
More from Topic 7.1
All flashcards in this topic
Computer Science exam skills
Paper structures & tips
Track your progress with spaced repetition
Sign up free — Aimnova tells you exactly which cards to review and when, so you remember everything before your IB exam.
Start Free