Zum Inhalt springen
Brainlag

Design

Farbe

Object-oriented programming

Informatik A-level Updated Wed 7 Oct 2026

Object-oriented programming builds a program from objects that bundle data with the code that acts on it. The vocabulary is where most marks are, so learn each term with a short example.

Part 1 of 3: Learn it

In short

  1. A class is a blueprint; an object is one instance of it, made by the constructor.
  2. Encapsulation keeps attributes private and gives access through methods.
  3. Inheritance lets a subclass reuse a parent class; polymorphism lets a subclass override a method.

Where this is in your specification

Spec points: AQA 7517 4.1.2.3, OCR H446 1.2.4

BoardTopic: Object-oriented programming
AQA 75174.1.2.3
OCR H4461.2.4 (object-oriented languages)

Classes and objects

class Pet
private name
public procedure new(givenName)
name = givenName
public function getName()
return name
endclass
rex = new Pet("Rex")

Pet is the class. name is an attribute, getName is a method, and new is the constructor that runs when an object is created. rex is an object: creating it is called instantiation.

Encapsulation

Attributes are usually private, so other code can only change them through public methods (getters and setters). A setter can check a value before storing it, which protects the object's data from invalid changes and lets the inside of the class change without breaking other code.

Inheritance and polymorphism

  • Inheritance: class Dog inherits Pet. A Dog has everything a Pet has, plus its own extra attributes and methods. It describes an "is a" relationship.
  • Overriding: Dog can define its own version of a method that Pet already has, such as describe().
  • Polymorphism: code can call describe() on any Pet, and each object runs its own version.

Class diagrams

A class is drawn as a box with three parts: name, attributes, methods. A minus sign marks private members and a plus sign public ones. An arrow with an open triangle points from a subclass to its parent.

Quick check

What is instantiation?

Show the answer

Creating an object from a class.

Part 2 of 3: See it worked

Worked examples

Example 1

Explain why the name attribute of Pet is private and accessed through getName().

  1. Private means code outside the class cannot change it directly
  2. Changes can only happen through methods, which can validate them
  3. This is encapsulation

Answer: Encapsulation: it protects the data from unintended changes and hides how the class works inside.

Example 2

Cat and Dog both inherit from Pet, and each overrides speak(). A list holds two Cats and a Dog. What happens when a loop calls speak() on each item?

  1. Each object belongs to its own subclass
  2. At run time, the subclass's own speak() is used
  3. So the cats run Cat's version and the dog runs Dog's

Answer: Each object uses its own version of speak(): this is polymorphism.

Common mistakes

  • Using class and object as if they mean the same thing.
  • Saying encapsulation just means putting code in a class, without mentioning access to data.
  • Using inheritance for "has a" relationships.
  • Confusing overriding (same method name in a subclass) with overloading.
Quick check

What does a constructor do?

Show the answer

It runs when an object is created and sets up its initial attribute values.

Part 3 of 3: Test yourself

Check yourself

Answer each one in your head or on paper first, then open it to check.

What is instantiation?

Creating an object from a class.

What does a constructor do?

It runs when an object is created and sets up its initial attribute values.

Give one advantage of inheritance.

Code in the parent class is reused, so it is written and tested once.

Jobs that use this

Each link opens the job profile on the National Careers Service (England). In the rest of the UK: My World of Work (Scotland), Careers Wales, nidirect careers (Northern Ireland).

Diese Lernzettel sind auf Englisch, weil sie britischen Prüfungslehrplänen folgen.

Full lessons and marked practice for this course are coming soon to Brainlag Learn. See courses