OOAD Princhiples Q/A #1

Question:What is inheritance? Discuss types of inheritance with example.
Answer:
Inheritance  is the mechanism to allow a class A to inherit properties of class b i.e  A inherits from B. Objects of class A thus have accesses to attribute and methods of class B without the need to redefine them.  If class A inherits from class B , then B is called super class of A and A is called subclass of B. Supper classes are also called base classes or parents classes. Subclasses may be called derived classes or child classes.
Inheritance is one of the most powerful features of object oriented programming. Most important advantages of inheritance are:

Reusability - Inheritance allows deriving new classes from existing classes without modifying it. This helps in reusability of information in the child class as well as adding extra functionality in to it.
Saves times and efforts - The concept of reusability achieved by inheritance saves a lot of programmer time and effort as the main code written can be reused in various  situations as needed.
Closeness with the real world - Inheritance allows the capability to express the inheritance relationship and ensures closeness with  the real world models.
Easy modification - Inheritance allows modification to be done in an easier manner.
Transitive Nature of inheritance - If a class A inherits properties of another class B then all subclasses of A will automatically inherits the properties of B. This concept is called transitive nature  of inheritance.

Reusability - Inheritance allows deriving new classes from existing classes without modifying it. This helps in reusability of information in the child class as well as adding extra functionality in to it.
Reusability - Inheritance allows deriving new classes from existing classes without modifying it. This helps in reusability of information in the child class as well as adding extra functionality in to it.
Saves times and efforts - The concept of reusability achieved by inheritance saves a lot of programmer time and effort as the main code written can be reused in various  situations as needed.
Saves times and efforts - The concept of reusability achieved by inheritance saves a lot of programmer time and effort as the main code written can be reused in various  situations as needed.
Closeness with the real world - Inheritance allows the capability to express the inheritance relationship and ensures closeness with  the real world models.
Closeness with the real world - Inheritance allows the capability to express the inheritance relationship and ensures closeness with  the real world models.
Easy modification - Inheritance allows modification to be done in an easier manner.
Easy modification - Inheritance allows modification to be done in an easier manner.
Transitive Nature of inheritance - If a class A inherits properties of another class B then all subclasses of A will automatically inherits the properties of B. This concept is called transitive nature  of inheritance.
Transitive Nature of inheritance - If a class A inherits properties of another class B then all subclasses of A will automatically inherits the properties of B. This concept is called transitive nature  of inheritance.
class subclass: visibility_mode  superclass_name 
{
...
}
Here class is keyword. superclass_name is the neme of the derived class which is a valid identifier. Visibility modes are of three types public, private and protected.
Various types of inheritance are supported by C++. These are:

Single Inheritance - When a subclass inherits properties from one base class, it is called single inheritance. In single inheritance , there is only one base class and one derived class. 
Multiple Inheritance - When a subclass inherits properties from multiple base classes, it is known as multiple inheritance. In multiple Inheritance , there is only one derived  class and several base  classes.
Hierarchical Inheritance - When two or more subclasses inherit properties  from  a single base class, It is known as  Hierarchical  inheritance . In hierarchical inheritance , the feature of one class may be inherited by more then one class.
Multilevel Inheritance - In multilevel Inheritance , A class is derived from an already derived class. The transitive nature of inheritance is reflected by this form of inheritance.
Hybrid Inheritance - When two or more type of inheritance are required to code a program, such type of inheritance  is called hybrid inheritance.
Figure shown below is a combination of multilevel  and multiple inheritance.

Single Inheritance - When a subclass inherits properties from one base class, it is called single inheritance. In single inheritance , there is only one base class and one derived class. 
Single Inheritance - When a subclass inherits properties from one base class, it is called single inheritance. In single inheritance , there is only one base class and one derived class. 
Multiple Inheritance - When a subclass inherits properties from multiple base classes, it is known as multiple inheritance. In multiple Inheritance , there is only one derived  class and several base  classes.
Multiple Inheritance - When a subclass inherits properties from multiple base classes, it is known as multiple inheritance. In multiple Inheritance , there is only one derived  class and several base  classes.
Hierarchical Inheritance - When two or more subclasses inherit properties  from  a single base class, It is known as  Hierarchical  inheritance . In hierarchical inheritance , the feature of one class may be inherited by more then one class.
Hierarchical Inheritance - When two or more subclasses inherit properties  from  a single base class, It is known as  Hierarchical  inheritance . In hierarchical inheritance , the feature of one class may be inherited by more then one class.
Multilevel Inheritance - In multilevel Inheritance , A class is derived from an already derived class. The transitive nature of inheritance is reflected by this form of inheritance.
Multilevel Inheritance - In multilevel Inheritance , A class is derived from an already derived class. The transitive nature of inheritance is reflected by this form of inheritance.
Hybrid Inheritance - When two or more type of inheritance are required to code a program, such type of inheritance  is called hybrid inheritance.
Figure shown below is a combination of multilevel  and multiple inheritance.
Hybrid Inheritance - When two or more type of inheritance are required to code a program, such type of inheritance  is called hybrid inheritance.
Figure shown below is a combination of multilevel  and multiple inheritance.

    14 Lectures 
     1.5 hours 

 Harshit Srivastava

    60 Lectures 
     8 hours 

 DigiFisk (Programming Is Fun)

    11 Lectures 
     35 mins

 Sandip Bhattacharya

    21 Lectures 
     2 hours 

 Pranjal Srivastava

    6 Lectures 
     43 mins

 Frahaan Hussain

    49 Lectures 
     4.5 hours 

 Abhilash Nelson
 Print
 Add Notes
 Bookmark this page