Inheritance Principle

Inheritance is a way of extending class. The new class (child class) builds logic on the top of the parent class (super class).

Here's an example:


Basically the child class can add, extend, rewrite or use the inherited logic from the parent.

For this example:

  • Added logic:
    • member - doorsCount (line 33)
    • parametrized constructor (line 42)
    • getter for doorsCount (line 58)
  • Extended logic:
    • representation method (line 51)
  • Entirely rewritten logic:
    • getInsuranceCost (line 36)
  • Not modified logic:
    • getMake (line 18)
    • getModel (line 23)