What is the difference between Single inheritance and multilevel inheritance?
Hey guys, I want to know what is the difference between Single Inheritance and multilevel inheritance in C++. I am not aware of the term inheritance in C++. I am aware with concepts of C programming but I did not find term inheritance in C programming. This is completely new term for me. So if anybody having any clue or any information then please let me know so that I could understand this term and clear my concepts.
Re: What is the difference between Single inheritance and multilevel inheritance?
Inheritance was defined as deriving a new class from the exiting base class. When only one class is derived from a single base class, the type of inheritance is called as single inheritance .A class which is inhering is known as derived class where as the class which is being inherited is called base class. In inheritance the properties of one class is inherited by other class. The class A is Base class and class B is the derived class. Let’s consider that we have class vehicle which is inherited by class taxi.
Re: What is the difference between Single inheritance and multilevel inheritance?
Code:
For ex :-
class A
{
public : int k;
public : void show ( )
{
cout < <k;
}
} ;
class B: public A
{
int j;
public : void disp ( )
{
cout << j <<” “<<k ;
}
} ;
main ( )
{
B Ob ;
Ob. show( );
Ob.disp( );
}
In the above program class B inherites class A. so all the public variable and function of class A will be inherited by class B. so the variable and function declared as public or protected will be available to class B.
Re: What is the difference between Single inheritance and multilevel inheritance?
When one class is inherited from other class which itself is inherited by other .Then such type of inheritance is known as multilevel inheritance. Means one class is base which has one derived class, and the derived class acts as base class for other and deriving some class. For EX: - class A is inherited by the class B and class B is inherited by class C. such kind of inheritance is known as multilevel inheritance.