
Using inheritance, we have to write the functions only one time instead of three times as we have inherited the rest of the three classes from the base class (Vehicle). Look at the below diagram in which the three classes are inherited from vehicle class: If we create a class Vehicle and write these three functions in it and inherit the rest of the classes from the vehicle class, then we can simply avoid the duplication of data and increase re-usability. To avoid this type of situation, inheritance is used. This increases the chances of error and data redundancy.
Worksheet 17 linked list introduction list stack ans code#
You can clearly see that the above process results in duplication of the same code 3 times. If we create these classes avoiding inheritance then we have to write all of these functions in each of the three classes as shown below figure: The methods fuelAmount(), capacity(), applyBrakes() will be the same for all three classes. You need to create classes for Bus, Car, and Truck.

The article is divided into the following subtopics:Ĭonsider a group of vehicles.


Inheritance is a feature or a process in which, new classes are created from the existing classes. ISRO CS Syllabus for Scientist/Engineer Exam.ISRO CS Original Papers and Official Keys.GATE CS Original Papers and Official Keys.
