Topic B3 is HL only (AHL). Object-oriented programming lets you model real-world things as objects that bundle their data and their behaviours together, instead of scattering them across many separate variables and lists. This unit covers the building blocks the book starts with: what a class is, the attributes, methods and constructor inside it, how you instantiate an object from a class, and the difference between static and non-static members.
Slide 1 / 4
Classes and objects
A class is a blueprint or plan for an object. It identifies the instance variables (the attributes) and the methods (the behaviours) that the object will have.
An object is an instantiated class: the constructor has been called, the instance variables have been given values, and the object now exists in memory with its own identifier.
One class can produce many objects. A Bird class can create a rainbow lorikeet object and a puffin object, each holding its own values but sharing the same structure.
Attributes become the instance variables (the data you store) and behaviours become the methods (what the object can do).
Check you've got it
0/4
1. In object-oriented programming, what is a class?
2. What happens when a class is instantiated?
3. In a Java constructor you see the line this.name = name; What is the purpose of the keyword this?
4. A Book class has a static variable booksBorrowed that starts at 0 and is increased by 1 each time setBorrowed(true) is called. Three Book objects are created and setBorrowed(true) is called on two of them. What does Book.getNumberOfBooksBorrowed() return?
Free revision content. Multiple-choice answers are marked instantly. Written answers are marked by AI on /free-mark.