For example, a programmer can create a base class named fruit and define derived classes as mango, orange, banana, etc. Each of these derived classes, (mango, orange, banana, etc.) has all the features of the base class (fruit) with additional attributes or features specific to these newly created derived classes. Mango would have its own defined features, orange would have its own defined features, banana would have its own defined features, etc.
This concept of Inheritance leads to the concept of polymorphism.
Features or Advantages of Inheritance:
1)Reusability:Inheritance helps the code to be reused in many situations. The base class is defined and once it is compiled, it need not be reworked. Using the concept of inheritance, the programmer can create as many derived classes from the base class as needed while adding specific features to each derived class as needed.
2)Saves Time and Effort:
The above concept of reusability achieved by inheritance saves the programmer time and effort. Since the main code written can be reused in various situations as needed.
3)Increases Program Structure which results in greater reliability.
General Format for implementing the concept of Inheritance:
class derived_classname: access specifier baseclassnameProperties of access specifier:

7:51 AM
Alice


0 comments:
Post a Comment