How do encapsulation, inheritance, polymorphism and abstraction make object oriented code safer and more reusable?
The four pillars of object orientation - encapsulation with access modifiers, inheritance and class hierarchies, polymorphism through method overriding, and abstraction.
A CCEA A-Level Software Systems Development answer on the four pillars of object orientation: encapsulation and access modifiers, inheritance and class hierarchies, polymorphism through overriding, and abstraction, and the benefits each brings.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this dot point is asking
CCEA expects you to explain the four pillars of the object oriented paradigm: encapsulation, inheritance, polymorphism and abstraction. For each you must give a precise definition, the mechanism that achieves it (access modifiers, class hierarchies, method overriding), and a benefit to the developer. These concepts recur throughout the course and are favourite extended-answer questions, so learn the keywords exactly.
The answer
Encapsulation
Access is controlled by access modifiers. A private member is reachable only from inside its own class; a public member is reachable from anywhere. Private attributes are read and written through public accessor (getter) and mutator (setter) methods, which can validate input before it is stored.
Inheritance
Inheritance lets a new class, the subclass (child), acquire the attributes and methods of an existing class, the superclass (parent), and then add or modify features of its own. This builds a class hierarchy in which shared behaviour lives near the top and specialised behaviour lower down. Its main benefit is code reuse: common features are written once and shared.
class Account // superclass
attributes: balance
methods: deposit(a), withdraw(a)
class SavingsAccount extends Account // subclass
attributes: interestRate
methods: addInterest() // new behaviour, plus all of Account's
Polymorphism and abstraction
Polymorphism ("many forms") means the same method name behaves differently depending on the object it is called on. It is achieved by method overriding: a subclass redefines an inherited method with the same name and parameters but a different body. A call such as shape.area() then runs the version belonging to the object's actual class.
Abstraction is the modelling of only the essential features of a thing while hiding unnecessary detail. A class is itself an abstraction: a Car class exposes accelerate() and brake() without the driver needing to know how the engine works. Abstraction reduces complexity and lets developers reason at a high level.
Worked example: a shape hierarchy using all four pillars
Examples in context
Example 1. A staff payroll system. A general Employee superclass holds name and salary (private) with a calculatePay() method. Manager and SalesRep subclasses inherit these and override calculatePay() to add a bonus or commission. A payroll loop calls calculatePay() on a list of Employee objects, and polymorphism runs the right rule for each, while encapsulation keeps salaries from being altered directly.
Example 2. A drawing application. Every tool (pen, brush, eraser) is a subclass of an abstract Tool with an overridden apply() method. The canvas keeps a list of Tool objects and calls apply() without caring which tool it is. Abstraction lets new tools be added later just by writing another subclass, with no change to the canvas code.
Try this
Q1. State what is meant by encapsulation and name the access modifier used to hide an attribute. [2 marks]
- Cue. Bundling attributes with their methods and hiding the attributes from outside code; the modifier is
private.
Q2. A Vehicle class has a method move(). A Car subclass redefines move() with its own behaviour. Name this mechanism and the principle it supports. [2 marks]
- Cue. Method overriding; it supports polymorphism.
Q3. Give one benefit of abstraction to a developer working on a large system. [1 mark]
- Cue. It reduces complexity by exposing only essential features, so the developer can work at a high level without unnecessary detail.
Exam-style practice questions
Practice questions written in the style of CCEA exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
CCEA 20186 marksExplain the terms encapsulation and inheritance, and give one benefit of each to a software developer.Show worked answer →
Encapsulation means bundling an object's attributes and the methods that act on them into one unit, and restricting direct access to the attributes by marking them private. Outside code reaches the data only through public methods (getters and setters). A benefit is data protection and integrity: the attributes cannot be set to invalid values directly, because a setter can validate input before storing it, and the internal representation can change without breaking other code.
Inheritance lets a new class (the subclass or child) acquire the attributes and methods of an existing class (the superclass or parent), then add or change features of its own. For example a SavingsAccount can inherit balance, deposit() and withdraw() from a general Account class and add an interestRate attribute. A benefit is code reuse: common features are written once in the superclass and shared by every subclass, reducing duplication and making maintenance easier.
Markers reward a correct definition of each term, the keyword (private for encapsulation, parent and child for inheritance), and a genuine, distinct benefit for each.
CCEA 20224 marksExplain what is meant by polymorphism in object oriented programming, and describe how it is achieved through method overriding.Show worked answer →
Polymorphism means that the same method name can behave differently depending on the object it is called on. A single instruction such as shape.area() produces the correct result whether shape is a circle, a rectangle or a triangle, because each class supplies its own version of the method.
It is achieved through method overriding: a subclass redefines a method it inherited from its superclass, keeping the same name and parameters but giving a different implementation. For example a Shape superclass declares area(), and Circle, Rectangle and Triangle each override area() with the formula appropriate to that shape. When area() is called on an object, the version belonging to that object's actual class runs.
A benefit is flexibility: code can treat many different objects uniformly through a shared interface (for example a list of Shape objects), while each still behaves correctly.
Markers reward the idea of one name behaving differently per object, the link to overriding (same signature, different body in the subclass), and a sensible shape or animal example.
Related dot points
- Classes and objects, attributes and methods, instantiation, and how the object oriented paradigm models real-world entities.
A CCEA A-Level Software Systems Development answer on the core object oriented concepts: what a class and an object are, attributes and methods, instantiation, and how the paradigm models real-world entities.
- Methods, parameters and arguments, return values, variable scope, and common string-handling operations.
A CCEA A-Level Software Systems Development answer on methods and parameters: passing arguments, returning values, local and global scope, and common string-handling operations such as length, substring and concatenation.
- Primitive data types, variables and constants, arithmetic, relational and logical operators, operator precedence, and type conversion (casting).
A CCEA A-Level Software Systems Development answer on primitive data types, declaring variables and constants, arithmetic, relational and logical operators with precedence, and type conversion or casting.
- Validation techniques, test data categories (normal, boundary and erroneous), test plans, and the types of program error (syntax, run-time and logic).
A CCEA A-Level Software Systems Development answer on validation techniques, choosing normal, boundary and erroneous test data, building a test plan, and distinguishing syntax, run-time and logic errors.
Sources & how we know this
- CCEA GCE Software Systems Development specification — CCEA (2016)