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

Classes and objects

Practice Flashcards

Flip to reveal answers
Card 1 of 57.1.4
7.1.4
Question

What is the difference between defining a class and instantiating an object?

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 — Classes and objects

Sign up free to track progress and get spaced-repetition review schedules.

Card 1comparison

Question

What is the difference between defining a class and instantiating an object?

Answer

Defining writes the template once, saying what every one will have and can do. Instantiating creates an actual object from that template, with its own values, as often as needed.

Card 2definition

Question

What does a constructor do?

Answer

It runs automatically when an object is created and gives every attribute a value, so no object ever exists in an unfinished state. It can also refuse invalid values before the object exists.

Card 3definition

Question

What does self refer to?

Answer

The object the method was called on. self.title is this particular book's title, which is what lets one method definition serve every object of the class.

Card 4concept

Question

Why is not every attribute a constructor parameter?

Answer

Some have a single correct starting value. A new book is never on loan, so onLoan is set to False inside the constructor rather than asked for — which removes a chance to get it wrong.

Card 5concept

Question

What happens if a constructor misses an attribute?

Answer

The object exists with a missing value, and the failure appears much later, somewhere that has nothing to do with the cause — which makes it hard to trace.

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 Classes and objects Flashcards | 7.1.4 | Aimnova