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

  1. LearnThe parts of a class
  2. CodeA complete class
  3. CodeCreating and using objects
  4. CodeWithout toString / __str__
  5. CheckQuick check
  6. CodeA list of objects
  7. CodeTry it: a Dog class
  8. ExamWorked exam answer
  9. ReviewMistakes examiners see
  10. Exam practiceExam-style questions

Ends with 4 exam-style questions worth 12 marks, with a self-marking markscheme.