SLIDE 1 / 12
CSZone.co.uk
OCR H446 · Component 1 · 1.2.4

Object-Oriented
Programming (OOP)

OCR A Level Computer Science · cszone.co.uk
H446 SpecA Level
Learning Objectives

By the end of this topic you will be able to:

Define class, object, attribute and method
Explain encapsulation, inheritance, polymorphism and abstraction
Describe constructors and instantiation
Understand class diagrams and write/trace OOP code
Classes & Objects

Classes, Objects, Attributes and Methods

Class
A blueprint / template that defines the attributes (data) and methods (behaviour) that all objects of that type will have. A class is a definition, not a thing itself.
Object (Instance)
A specific instance of a class. Created (instantiated) from the class blueprint. Multiple objects can be created from one class, each with its own attribute values.
Attribute
A variable that belongs to an object and stores its state (e.g. name, age, balance).
Method
A function defined inside a class that operates on the object's attributes (e.g. deposit(), getBalance()).
Encapsulation

Encapsulation

Encapsulation is the bundling of attributes and methods inside a class, and restricting direct access to an object's internal state from outside the class. This is achieved through access modifiers.
Access Modifiers
Public: accessible from anywhere
Private: only accessible from within the class itself
Protected: accessible from the class and its subclasses
Getters & Setters
Public methods used to read (get) and write (set) private attributes. This enforces validation and maintains control over how internal data is changed.
Inheritance

Inheritance

Inheritance allows a subclass (derived class) to inherit all the attributes and methods of a superclass (base class), and add or override additional behaviour. Promotes code reuse.
Example: Animal is a superclass with attribute name and method speak(). Dog inherits from Animal and adds method fetch(). Dog does not need to redefine name.
Single inheritance: one parent class. Multiple inheritance: inherits from multiple parents (supported in Python, not Java).
Constructor chaining: a subclass constructor typically calls the parent class constructor (using super()) to initialise inherited attributes before adding its own.
Polymorphism & Abstraction

Polymorphism and Abstraction

Polymorphism
Polymorphism means “many forms” — the same method name behaves differently depending on the object it is called on. A speak() method in Dog returns “Woof” while in Cat it returns “Meow”. Method overriding achieves this.
Abstraction
Abstraction hides the complex implementation details from the user and exposes only the necessary interface. Abstract classes define method signatures that subclasses must implement, without providing the implementation themselves.
Constructor: a special method called when an object is instantiated. Initialises the object’s attributes. In Python: def __init__(self, name): self.name = name
Exam Practice
OCR H446 Style · 5 marks
Describe the four main principles of object-oriented programming: encapsulation, inheritance, polymorphism and abstraction.
[5 marks — 1 mark each + 1 for quality]
1
Encapsulation: attributes and methods are bundled inside a class; internal state is made private and accessed through public getter/setter methods, controlling how data is used.
1
Inheritance: a subclass inherits all attributes and methods from its superclass, allowing code reuse and extension without modifying the original class.
1
Polymorphism: the same method name behaves differently depending on which object it is called on, achieved through method overriding in subclasses.
1
Abstraction: complex implementation details are hidden; only the interface (method signatures) is exposed. Abstract classes force subclasses to provide concrete implementations.
Common Mistakes

Don’t Lose Marks

!
Confusing a class with an object — a class is the blueprint/template (the definition). An object is a specific instance created from the class. A class can produce many objects, each with their own attribute values.
!
Saying encapsulation just means private variables — it means bundling data and methods together AND restricting access. The combination of both is the key concept, not just one element.
!
Confusing inheritance and polymorphism: inheritance is about reusing code from a parent class; polymorphism is about the same method name having different behaviours in different subclasses. They work together but are distinct concepts.
1.2.4e Complete
Well done! ✓
Object-Oriented Programming (OOP)
Return to lesson to continue