Practice Flashcards
Flip to reveal answersWhat is the difference between defining a class and instantiating an object?
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.
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.
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.
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.
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.
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.
Read the notes
Full study notes for Classes and objects
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