Inheritance:
It is process by which
object of one class acquire the properties and functionalities of object of
another class.
The class that is predefined
is called as base or super class, and the class which use the existing class is
called as derived class or sub class.
The various type of
inheritance those are provided by C++ is as follows:
i.
Single Inheritance
ii.
Multi level Inheritance
iii.
Multiple Inheritance
iv.
Hierarchical Inheritance
v.
Hybrid Inheritance
i.
Single Inheritance:
In this, there is only one super class & only one sub
class, means they have one to one communication between them.
ii.
Multi level Inheritance:
In this, a derived class can also inherited by another class,
means when a derived class again will be inherited by another class then it
create multiple levels of class.
iii.
Multiple inheritance:
In this, a class inherits the features of two or more base
classes.
iv.
Hierarchical Inheritance:
In this, a base class has two or more sub classes or when a
base class is used or inherited by many sub classes, it is called hierarchical
inheritance.
v.
Hybrid Inheritance:
In this type, it is a mixture of two or more inheritance. A
code may contain two or three types of inheritance in a single call.
Derived
Class OR Inheritance type
|
||||
Base Class
|
Public
|
Protected
|
Private
|
|
Public
|
Public
|
Protected
|
Not
Inherit
|
|
Protected
|
Protected
|
Protected
|
Not Inherit
|
|
Private
|
Private
|
Private
|
Not
Inherit
|
class college
{
protected:
char clg_name[10];
public:
void clg_getvalue()
{
cout<<”value of college”;
cin>>clg_name;
}
};
class dept:public college
{
private:
char dept_name[10];
public:
void dept_getvalue()
{
cout<<”value of dept”;
cin>>dept_name;
}
void display()
{
cout<<”College name
”<<clg_name;
cout<<”Department name
”<<dept_name;
}
};
void main()
{
dept obj;
clrscr();
obj.clg_getvalue();
obj.dept_getvalue();
obj.display();
getch();
}
0 comments:
Post a Comment