B3.1 Fundamentals of OOP for a single classB3.1.4
Defining Classes and Instantiating Objects
Construct code to define classes and instantiate objects
SL + HL≈ 65 minCommand term: ConstructPremium
In this lesson
- Writing a class with private attributes, a constructor, accessors, mutators and a toString / __str__ method
- Explaining the role of the constructor in setting an object’s initial state
- Instantiating objects and calling their methods with dot notation
- Storing objects in a list and processing them with loops and selection
This lesson is part of Premium
Every topic has one free lesson. Premium unlocks every interactive lesson, the exam-style questions at the end of each one, and the rest of Praxis IB.
What's inside
- LearnThe parts of a class
- CodeA complete class
- CodeCreating and using objects
- CodeWithout toString / __str__
- CheckQuick check
- CodeA list of objects
- CodeTry it: a Dog class
- ExamWorked exam answer
- ReviewMistakes examiners see
- Exam practiceExam-style questions
Ends with 4 exam-style questions worth 12 marks, with a self-marking markscheme.