Inheritance
Inheritance is a mechanism that helps developers through the process of implementing complex hierarchical data structures. All inherited features become part of the new class. To put it simply, a class can inherit properties and methods from another class. The class which is inherited is called a parent class or super class. The new class which inherits another class is called a child class.
Note
The inheritance is applicable to classes only.
Each class which inherits from another class can provide a specific implementation of the inherited features. All other functions, properties, subscripts, and so on, can be accessed from the child class.
Base class
Every class which doesn't have a super class is called a base class. In contrast with other programming languages, there is no universal class which all classes inherit from. So, every base class can be used as a super class (except if we explicitly forbid a class to be inherited).
Let's try to create a subclass of our class Ship
:
/...