उदाहरण सहित मल्टीलेवल इनहेरिटेन्स मल्टीपल इनहेरिटेन्स की व्याख्या कीजिए।
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
मल्टीलेवल इनहेरिटेन्स जिस प्रकार सिंगल इनहेरिटेन्स में एक बेस क्लास से एक डिराइव्ड क्लास बनाई जाती है। कभी-कभी डिराइब्ड क्लास से भी एक अन्य क्लास बनाई जा सकती है अर्थात् डिराइब्ड क्लास पुनः एक बेस क्लास की तरह कार्य करे, तो इस प्रकार के इनहेरिटेन्स को मल्टीलेवल इनहेरिटेन्स कहते हैं।
उदाहरण
#include<iostream.h>
class Person
{
protected:
char name;
public:
void get1()
{
cout<<“Enter your Name\n”; cin>>name;
}
};
class Emp: public Person
{
protected:
int basic;
public:
void get2()
{
cout<<“Enter your Basic\n”; cin>>basic;
}
};
class Manager: public Emp
{
protected:
int deptcode;
public:
void display()
{
cout<<“Name is “<<name;
cout<<“\nBasic “<<basic;
}
};
void main()
{
Manager obj;
obj.get1();
obj.get2();
obj.display();
getch();
}
आउटपुट
Enter your Name
H
Enter your Basic
25000
Name is H
Basic 25000
मल्टीपल इनहेरिटेन्स इस प्रकार के इनहेरिटेन्स में एक से अधिक बेस क्लासेज की सहायता से एक डिराइव्ड क्लास बनाई जाती है।
#include<iostream.h>
class Expdet
{
protected:
char name;
public:
void expr()
{
cout<<“Enter your Name”<<end1; cin>>name;
}
};
class Saldet
{
protected:
int salary;
public:
void sal()
{
cout<<“Enter your Salary”<<end1; cin>>salary;
}
};
class Promotion : public Expdet, public Saldet
{
public:
void promote()
{
if (salary> = 20000)
cout<<“PROMOTED FOR HIGHER GRADE”;
else
cout<<“CANNOT BE PROMOTED”;
}
};
void main()
{
Promotion obj;
obj . expr();
obj . sal();
obj . promote();
}
आउटपुट
Enter your Name
J
Enter your Salary
23000
PROMOTED FOR HIGHER GRADE