Level 2

Inheritance

views

6:04
Suppose, you want to create classes for car, bus and truck. When you start writing the code for the class, you will realise that each one of them has 4 wheels, one engine, accelerator and brakes. In order to avoid writing these again and again, we will be making use of inheritance. To do this we will create a class called vehicle. This class is called the base class. We can now derive a class from this base class for each type of the vehicle. This is called as the derived class.