Write a C++ program for incorporating multi-level inheritance.
AIM:
Write
a C++ program for incorporating multi-level inheritance.
THEORY:
Inheritance is the process of inheriting properties of
objects of one class by objects of another class. The class which
inherits the properties of another class is called Derived or Child
or Sub class and the class whose properties are inherited
is called Base or Parent or Super class. When a class is
derived from a class which is also derived from another class, i.e. a class
having more than one parent classes, such inheritance is called Multilevel Inheritance.
The level of inheritance can be extended to any number of level depending upon
the relation. Multilevel inheritance is similar to relation between
grandfather, father and child.
SOURCE
CODE:
#include<iostream>
using namespace std;
class A{
protected:
char
name[20];
int
age;
};
class B:public A{
protected:
int
h,w;
};
class C:public B{
public:
char
g;
void
get_data(){
cout<<"\n enter name and
age:";
cin>>name>>age;
cout<<"\n enter weight and
height:";
cin>>w>>h;
cout<<"\n enter
gender:";
cin>>g;
}
void
show(){
cout<<name<<endl<<age<<endl;
cout<<w<<endl<<h<<endl;
cout<<g<<endl;
}
};
int main(){
C
ob;
ob.get_data();
ob.show();
}
Labels: oop through c++ lab
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home