Inheritance
A mechanism enabling classes to inherit attributes and methods from parent classes, promoting code reuse and hierarchy. Inheritance creates is-a relationships between classes, where subclasses specialize parent classes. Subclasses override parent methods to provide specialized behavior. Multiple inheritance (supported by some languages) enables inheriting from multiple parents.
Real World
In the Uber app, an ElectricVehicle class inherits from a Vehicle parent class, gaining attributes like registration and location, while adding its own batteryLevel attribute and chargeStatus() method.
Exam Focus
Use 'is-a' language to justify inheritance relationships; examiners penalise 'has-a' relationships modelled as inheritance.
How well did you know this?