Lecture notes on



Download 232,82 Kb.
bet28/45
Sana07.07.2022
Hajmi232,82 Kb.
#755880
1   ...   24   25   26   27   28   29   30   31   ...   45
Bog'liq
285 OOPS lecture notes Complete-конвертирован

Student Activity

  1. Define Inheritance. What is the inheritance mechanism in C++?

  2. What are the advantage of Inheritance?

  3. What should be the structure of a class when it has to be a base for other classes?

A member function of a derived class.

LECTURE-27


Multilevel Inheritance
When the inheritance is such that, the class A serves as a base class for a derived class B which in turn serves as a base class for the derived class C. This type of inheritance is called ‘MULTILEVEL INHERITENCE’. The class B is known as the ‘INTERMEDIATE BASE CLASS’ since it provides a link for the inheritance between A and C. The chain ABC is called ‘ITNHERITENCE*PATH’ for e.g.
Base class

Inheritance path
Intermediate base class



Derived class

The declaration for the same would be: Class A


{
//body
}
Class B : public A
{
//body
}
Class C : public B
{
//body
}

This declaration will form the different levels of inheritance. Following program exhibits the multilevel inheritance.


#include #include
class worker // Base class declaration
{
int age;
char name [20] ; public;
void get( ) ;

void show( ) ;
}

void worker: get ( )


{
cout << “your name please” ; cin >> name;
cout << “your age please” ;
}
void worker : : show ( )
{
cout << “In my name is : “ <}
class manager : public worker //Intermediate base class derived
{ //publicly from the base class int now;
public:
void get ( ) ; void show( ) ;
};
void manager :: get ( )
{
worker : :get () ; //calling get ( ) fn. of base class cout << “no. of workers under you:”;
cin >> now;
}
void manager : : show ( )
{
worker : : show ( ) ; //calling show ( ) fn. of base class cout << “In no. of workers under me are: “<< now;
}
class ceo: public manager //declaration of derived class
{ //publicly inherited from the
int nom; //intermediate base class public:
void get ( ) ; void show ( ) ;
};
void ceo : : get ( )
{
manager : : get ( ) ;
cout << “no. of managers under you are:”; cin >> nom;
}
void manager : : show ( )
{
cout << “In the no. of managers under me are: In”; cout << “nom;
}

main ( )
{


clrscr ( ) ;
ceo cl ;
cl.get ( ) ; cout << “\n\n”; cl.show ( ) ;
}

Worker





Private:
int age;
char name[20];

Protected:

Private:
int age;
char name[20];




Download 232,82 Kb.

Do'stlaringiz bilan baham:
1   ...   24   25   26   27   28   29   30   31   ...   45




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish