Abstract


  • Extending from existing OOP Class, the child classes take up all the properties and methods of their parent classes, building up on existing abstraction

Avoid Overusing Inheritance

Inheritance should be used only when a clear hierarchical relationship and shared behaviours exist between the parent (or base) class and the child (or derived) class.

Otherwise, consider using interfaces and composition which are generally more flexible.

Inheritance subtyping relationship

If inherits from , then . is a subtype of .

Multiple inheritance

When a subclass is able to inherit from multiple super classes. This leads to the diamond problem .

Java avoid multiple inheritance uses OOP Abstract Method. This can be proved with Proof by Contradiction (矛盾证明法).

”Is-a” Relationship


  • “A subclass is a superclass”, we mean that the subclass inherits from the superclass. This implies that the subclass can be used wherever the superclass is expected, adhering to the “is-a” relationship

A less abstracted explanation

Consider a superclass Animal and a subclass Dog. In this scenario, a Dog is an Animal. This means Dog inherits all the characteristics (methods and fields) of Animal. During compilation, a Dog object can be assigned the Animal data type and utilise methods defined in Animal, potentially with modifications through method overriding in the Dog class.

This concept promotes polymorphism, allowing Dog objects to be treated as instances of their superclass Animal.