Back to Topic 7.1 — OOP: a single class
7.1.3Computer Science SL5 flashcards

Static vs non-static

Practice Flashcards

Flip to reveal answers
Card 1 of 57.1.3
7.1.3
Question

What is the difference between a static and a non-static variable?

Click to reveal answer

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.

Card 1comparison

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.

Card 2concept

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.

Card 3comparison

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.

Card 4concept

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.

Card 5process

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.

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
IB Computer Science Static vs non-static Flashcards | 7.1.3 | Aimnova