Multilevel Inheritance in C++ by R4R Team

What is Inheritance in C++ :
In C++,
-Inheritance is a process in which one object acquires all the properties and behaviors of its parent object automatically. In such way, you can reuse, extend or modify the attributes and behaviors which are defined in other class.

Type of Inheritance in C++:
-Single Inheritance
-Multiple Inheritance
-Multilevel Inheritance
-Hierarchical inheritance
-Hybrid inheritance

Multilevel Inheritance:
-When child class work as parent for another third class then it is called as Multi-level Inheritance.
Syntax-
class one
{
};
class two:public one
{
};
class three:public two
{
};

program:

#include < iostream>
using namespace std;
class Animal{
public:
void drink() {
cout<<"Drinking.."<< endl;
}
};
class Dog: public Animal
{
public:
void eat(){
cout<<"Eating.."<< endl;
}
};
class BabyDog: public Dog
{
public:
void donothing() {
cout<<"Nothing";
}
};
int main(void) {
BabyDog d1;
d1.drink();
d1.eat();
d1.donothing();
return 0;
}


output-

Drinking
Eating
Nothing




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!