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:
    • getter for doorsCount (line 38)
  • Extended logic:
    • representation method (line 33)
  • Entirely rewritten logic:
    • getInsuranceCost (line 23)
  • Not modified logic:
    • getter for make (line 8)
    • getter for model (line 14)
    • setter for make (line 11)
    • setter for model (line 17)