← Back to subjects
⭐ 0
IB Diploma Computer Science HL Β· Option D / OOP β€” Object-oriented programming (HL)
Mini-Lesson

Object-oriented programming

This HL programming topic covers object-oriented programming (OOP): how objects and classes work, and the four pillars β€” encapsulation, inheritance, polymorphism and abstraction.

Work through each screen, answer the questions as you go (some are wordy, some are calculations) and collect ⭐ stars. Press Start when you are ready.

Objects

Objects and classes

A class is a blueprint; an object is an instance of a class. A class defines:

  • Attributes (fields) β€” the data each object holds.
  • Methods β€” the actions each object can perform.

Creating an object from a class is instantiation; a special method called the constructor sets up a new object’s starting state.

Quick check

Class vs object

?A class is called Car. You write myCar = new Car(). What is myCar?
Encapsulation

Encapsulation

Encapsulation bundles data and the methods that act on it inside one class, and restricts direct access to the data. Attributes are usually made private, reachable only through public getter and setter methods. This protects the data and hides the internal representation.

Quick check

Access modifier

?Which access modifier makes an attribute inaccessible from outside its own class?
Inheritance

Inheritance

Inheritance lets a subclass acquire the attributes and methods of a superclass, then add or change behaviour. It models an is-a relationship (a Dog is an Animal) and promotes code reuse. A subclass can override an inherited method to specialise it.

Quick check

Inheritance

?A class Dog extends a class Animal and reuses its methods. This relationship is best described as:
Polymorphism

Polymorphism

Polymorphism means one interface, many forms. A method such as draw() or speak() can be overridden so it behaves differently for each subclass, and the correct version is chosen at run time (dynamic dispatch). Method overloading defines several methods with the same name but different parameters.

Quick check

Polymorphism

?Different shape objects all have a method area() that computes area in their own way. When you call area() on any shape and get the right result, this is:
Abstraction

Abstraction

Abstraction hides complex detail and exposes only the essential features. An abstract class or interface declares what methods must exist without giving all the implementation, letting programmers work with simple, general concepts.

Sort it

Which pillar?

Tap an idea, then the OOP pillar it best fits.

πŸ” Encapsulation

πŸ‘ͺ Inheritance

🎭 Polymorphism / abstraction

UML

UML class diagrams

UML class diagrams show each class as a box with three parts: the name, the attributes, and the methods. Lines show relationships such as inheritance (an arrow to the superclass) and association. UML helps design and communicate an OOP solution before coding.

Match it

Match the OOP pillar

Tap a pillar on the left, then its definition.

Pillar
Definition
Constructors

Instantiation and constructors

Instantiation creates an object from a class. The constructor is a special method that runs automatically at creation to set the object’s starting attribute values. Each object then has its own copy of the instance attributes.

Quick check

Constructor

?What is the job of a constructor?
Static

Static and instance members

An instance attribute or method belongs to each object separately. A static (class) member belongs to the class as a whole and is shared by every object β€” useful for counters or constants.

Advantages

Advantages of OOP

OOP encourages modular, reusable code. Encapsulation protects data, inheritance avoids repetition, and objects map naturally onto real-world entities, which makes large programs easier to maintain and extend. A trade-off is added design complexity for small programs.

Quick check

OOP advantage

?Which is a genuine advantage of object-oriented programming?
Recap

The big ideas to know

Class vs object: blueprint vs instance; constructor sets up state

Encapsulation: private data, public getters and setters

Inheritance: subclass is-a superclass; code reuse and overriding

Polymorphism: one interface, many forms; overriding and overloading

Abstraction: hide detail, expose essentials (abstract classes, interfaces)

UML: class boxes with name, attributes and methods

You have covered the OOP HL programming topic. Press Finish to see your score.

πŸ†

Mini-lesson complete!

⭐⭐⭐

You have worked through Object-oriented programming. πŸŽ‰

Your stars: 0 / 0

Next: test yourself in the Evaluate stage Confidence Quiz, then lock it in with Verify.

πŸ“£ Smashed it? Share your score

Challenge a mate to beat your stars, or show a parent how you got on.

β†’ Back to all subjects