3. What is Inheritance???
It is very powerful feature in OOP.
It is a concept in which the properties
of one class are available for other
class.
The class that is being inherited is
called super class.
The class that inherits the properties
and functions of super class is called
sub class.
5. Multilevel Inheritance
In this one class is inherit from base
class.
Then this derived class becomes base
class of another class.
Thus the class in center is called
Intermediate class.
12. Multiple Inheritance:
In this type of inheritance there are
more than one base classes.
And one class is inherit from these
base classes.
The derived class has all the public
and protected properties of all base
classes.
These base classes are separated by
commas in syntax.
14. Syntax:
Class A
{….};
Class B
{…};
Class C :public A , Public B
{….};
15. Example program
#include<iostream>
using namespace std;
class father
{
private:
string name;
int phone_No;
public:
void function()
{
cout<<"father function....."<<endl;
}
};
class mother
public:
void cook()
{
cout<<"mother cook food...."<<endl;
}
};
16. class son
public:
void learn()
{
cout<<"son learn from books....."<<endl;
}
};
int main()
{
son s1;
s1.function();
s1.cook();
s1.learn();
system("pause");
}
17. Hierarchical Inheritance:
In this every class has only one base
class.
But a base class has many sub
classes.
This form may b represent like a tree.
Each derived class serves as a base
class of lower classes.
19. Example program
#include<iostream>
using namespace std;
class person
{
protected:
string name;
int phone;
public:
void setData(string n, int p)
{
name=n;
phone=p;
}
void showData()
{
cout<<"name and phone no are
"<<name<<endl<<phone<<endl;
}
};