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:
    • parametrized constructor (line 44)
    • getter for doorsCount (line 61)
  • Extended logic:
    • representation method (line 54)
  • Entirely rewritten logic:
    • getInsuranceCost (line 38)
  • Not modified logic:
    • getter for make (line 13)
    • getter for model (line 23)
    • The setters for make and model.