Implementing inheritance
Inheritance in a literal sense means acquiring the properties of a parent by the child, and it means the same in the case of OOP too. A new class can inherit the attributes and methods of a parent class and it can also have its own properties and methods. The new class that inherits the parent class will be called a child class or a subclass while the parent class can also be called a base class. The following is a simple representation of it:
Figure 2.5 – Inheritance
Extending our latest class definition of Branch
to have an individual class for NYC
—since it has multiple intra-city branches and it also has other properties of its own in addition to the Branch
class—we will be applying Inheritance to create a new subclass or child class named NYC
. It has propertiessuch as having multiple hierarchies of management. NYC has a regional manager and each branch has its own branch manager. For NYC, we will also add an...