Skip to main content
WalesComputer ScienceSyllabus dot point

What are the main programming paradigms, and how does object-oriented programming use classes, objects and inheritance?

Explain the procedural, object-oriented and declarative paradigms, and describe classes, objects, encapsulation, inheritance and polymorphism.

A focused answer to WJEC A-Level Computer Science Unit 3 programming paradigms, covering procedural, object-oriented and declarative programming, and the OOP concepts of classes, objects, encapsulation, inheritance and polymorphism.

Generated by Claude Opus 4.813 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. The answer
  3. Examples in context
  4. Try this

What this dot point is asking

WJEC wants you to explain the main programming paradigms (procedural, object-oriented and declarative) and to describe object-oriented programming in detail: classes and objects, encapsulation, inheritance and polymorphism. Paradigms are a substantial A2 topic in Unit 3, examined by definitions, by worked examples of class relationships, and by comparing when each paradigm suits a problem.

The answer

Procedural programming

Procedural code is straightforward and efficient for many tasks, but as programs grow, keeping data and the code that uses it separate can make large systems hard to maintain, which is one motivation for object orientation.

Object-oriented programming

OOP models real-world entities directly (a Car object has attributes and behaviours), promotes reuse through inheritance, and protects data integrity through encapsulation, which is why it dominates large software systems.

Declarative programming

Declarative programming describes what result is wanted rather than the step-by-step how. Logic programming states facts and rules and lets the system infer answers; functional programming builds programs from functions without changing state. SQL is a familiar declarative language: you state the data you want, not how to fetch it.

Comparing the paradigms

Examples in context

Example 1. A shape hierarchy
A superclass Shape defines an area() method; subclasses Circle and Rectangle override it with their own formulas. A program can hold a list of Shape references and call area() on each, with the right calculation running for each actual type. This is inheritance and polymorphism working together, and it shows why OOP suits families of related entities.
Example 2. Encapsulation protecting a bank balance
A BankAccount object keeps its balance private and exposes deposit() and withdraw() methods that enforce rules (no overdraft beyond a limit). Outside code cannot set the balance directly to an invalid value, which demonstrates how encapsulation protects data integrity, the benefit examiners want stated.
Example 3. Declarative SQL versus procedural search
To find all customers in a city, an SQL SELECT with a WHERE clause states the result declaratively; a procedural version would loop through every record comparing the city field. The declarative version is shorter and lets the database optimise the how, illustrating the contrast between describing what you want and coding each step.

Try this

Q1. State the difference between a class and an object. [2 marks]

  • Cue. A class is a template defining attributes and methods; an object is an instance created from that class.

Q2. Name the OOP concept that lets a subclass acquire the attributes and methods of a superclass. [1 mark]

  • Cue. Inheritance.

Exam-style practice questions

Practice questions written in the style of WJEC exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

WJEC 20204 marksExplain what is meant by encapsulation in object-oriented programming and state one benefit of it.
Show worked answer →

Define encapsulation, then give a genuine benefit.

Encapsulation is bundling an object's data (attributes) and the methods that operate on that data together within a class, and restricting direct access to the data from outside. The data is kept private and is read or changed only through public methods (getters and setters).

A benefit is that the internal representation can be changed without affecting code that uses the object, because that code only ever uses the public methods. It also protects the data from being put into an invalid state by outside code.

Markers reward the bundling of data and methods with controlled access, and a valid benefit such as protecting data integrity or allowing the internals to change without breaking other code.

WJEC 20224 marksA class Vehicle has a subclass Car. Explain how inheritance is used here, and explain what polymorphism would allow.
Show worked answer →

Explain inheritance in terms of the subclass, then explain polymorphism.

Inheritance lets the subclass Car inherit the attributes and methods of the superclass Vehicle, so Car automatically has Vehicle's general features (such as a speed attribute and a move method) and can add its own (such as a numberOfDoors attribute). This avoids rewriting shared code and models an "is a kind of" relationship.

Polymorphism would allow a method such as describe() to be overridden in Car so that the same method call behaves appropriately for the actual object type, so a collection of Vehicle references holding different subclasses each respond to describe() in their own way.

Markers reward inheritance as the subclass acquiring the superclass's attributes and methods (with the ability to add or override), and polymorphism as the same method call behaving according to the actual object type.

Related dot points

Sources & how we know this