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 two of the four pillars of OOP: inheritance and polymorphism. These concepts allow programmers to build hierarchies of related classes, promote code reuse, and write flexible programs that can work with objects of different types through a common interface.
Inheritance is the mechanism by which one class (the subclass or child class) can acquire the attributes and methods of another class (the superclass or parent class). The subclass can then extend or modify the inherited behaviour.
| Term | Definition |
|---|---|
| Superclass (Parent class) | The class being inherited from. |
| Subclass (Child class) | The class that inherits from the superclass. |
| Base class | Another term for superclass, especially the top-level class in a hierarchy. |
| Derived class | Another term for subclass. |
| "Is-a" relationship | Inheritance models an "is-a" relationship: a Dog is an Animal. |
CLASS Animal
PRIVATE name: STRING
PRIVATE sound: STRING
PUBLIC PROCEDURE new(n: STRING, s: STRING)
name = n
sound = s
END PROCEDURE
PUBLIC FUNCTION getName() RETURNS STRING
RETURN name
END FUNCTION
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.