You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson covers inheritance and polymorphism -- two of the four pillars of Object-Oriented Programming -- as required by the OCR A-Level Computer Science (H446) specification. These concepts enable code reuse, extensibility, and flexible design.
Inheritance is the mechanism by which one class (the subclass or child class) can inherit the attributes and methods of another class (the superclass or parent class). The subclass can then extend or modify the inherited behaviour.
Inheritance models an "is-a" relationship:
| Term | Definition |
|---|---|
| Superclass (parent/base class) | The class being inherited from. |
| Subclass (child/derived class) | The class that inherits from the superclass. |
| Inheritance | The mechanism of one class acquiring the attributes and methods of another. |
In single inheritance, a subclass inherits from exactly one superclass.
CLASS Animal
PRIVATE name: STRING
PRIVATE age: INTEGER
PUBLIC PROCEDURE new(n: STRING, a: INTEGER)
name = n
age = a
END PROCEDURE
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.