inheritance in c++
Inheritance in C++
Q.what is inheritance?
Define:- One of the most important features in object oriented programing is that of inheritance.it allows user to create a new class (derived class) from an existing class(base class).The derived class inherits all the features from the base class and can have additional features of its own.The derived class acquires the members(both variable and function)of the base class.these variable and functions become member of the derived class.
5 Different types of inheritance:-
1.Single inheritance
2.Multiple inheritance
3.Hierarchical inheritance
4.Multilevel inheritance
5.Hybrid/Virtual inheritance
1.Single inheritance:-in this type of inheritance one derived class inherits from only one base class.it very simplest form of inheritance.They have one to one communication between them:-
Example:-implementation of single inheritance
2.Multiple inheritance:-A single derived class may inherit from two or more than two base classes.This is known as multiple inheritance.multiple inheritance allows as to combine the features of several existing classes as a starting point for defining new classes.It is like a child inherit the physical feature of one parent and the intelligence of another.
3.Hierarchical inheritance:-In the hierarchical inheritance,multiple derived classes inherit from a single base class.
4.Multilevel inheritance:-The derived class inherits from a class,which in turn inherits from some other class.A class is derived from another derived class.The class A serves as a base class of the derived class B,which in turn serves as a base class for the derived class C.The class b is know as intermediate base class since it provides a link for the inheritance between A & C.
5.Hybrid inheritance:-Hybrid inheritance is combination of hierarchical,multilevel,multiple and single inheritance.
Q.what is inheritance?
Define:- One of the most important features in object oriented programing is that of inheritance.it allows user to create a new class (derived class) from an existing class(base class).The derived class inherits all the features from the base class and can have additional features of its own.The derived class acquires the members(both variable and function)of the base class.these variable and functions become member of the derived class.
5 Different types of inheritance:-
1.Single inheritance
2.Multiple inheritance
3.Hierarchical inheritance
4.Multilevel inheritance
5.Hybrid/Virtual inheritance
1.Single inheritance:-in this type of inheritance one derived class inherits from only one base class.it very simplest form of inheritance.They have one to one communication between them:-
2.Multiple inheritance:-A single derived class may inherit from two or more than two base classes.This is known as multiple inheritance.multiple inheritance allows as to combine the features of several existing classes as a starting point for defining new classes.It is like a child inherit the physical feature of one parent and the intelligence of another.
4.Multilevel inheritance:-The derived class inherits from a class,which in turn inherits from some other class.A class is derived from another derived class.The class A serves as a base class of the derived class B,which in turn serves as a base class for the derived class C.The class b is know as intermediate base class since it provides a link for the inheritance between A & C.
5.Hybrid inheritance:-Hybrid inheritance is combination of hierarchical,multilevel,multiple and single inheritance.
कोई टिप्पणी नहीं