Sei sulla pagina 1di 3

PREPARED BY R.

PADMA LAKSHMI ,PGT,DAV PUBLIC SCHOOL, BISTUPUR FOR THE BATCH XIIA1
AND XII-A3 -2019 Page 1

INHERITANCE
1. THE MECHANISM OF inheriting properties from one class to another class is
known as “inheritance”.

2. The class whichever is inherited from another class is known as derived class or
sub class

3. The class from which derived class is derived is known as base or super class

4. There are 5 kinds of inheritance

-Single : -Deriving one derived class from single base class is known as single
inheritance

-Multiple: -Deriving the derived class from more than 1 base class is known as
multiple inheritance

-Multilevel:-Deriving the derived class from another derived class is known as


multilevel inheritance.

-Hierarchical:-Deriving more than one derived class from single base class is
known as hierarchical class

-Hybrid:-The combination of above all kinds of inheritance is known as hybrid


inheritance

-There are 3 access specifiers :

1.Private:-not accessible to outside world, cannot be inherited

2.public:-Accessible to the outside world, can be inherited

3.protected:-Not accessible to the outside world, but it can be inherited


VISIBILITY MODE:-The visibility mode specifies the visibility of base class members

In the derived class

There are 3 visibilty modes

1)private-when the derived class is derived privately ,private members are not
inherited both public and protected members will be inherited to private access
specifier of derived class.

2)public-when the derived class is derived publicly, private members are not
inherited ,protected members of the base class will become protected members
of the derived class and public members of the base class will be public members
of the derived class.

3)protected-when the derived class is derived protectedly, private members are


not inherited ,protected members of the base class will become protected and
the public members of the base class will be protected members of the derived
class.

Base class Access Derived privately Derived publicly Derived


Specifier protectedly

Private X X X

Public PRIVATE PUBLIC PROTECTED

Protected PRIVATE PROTECTED PROTECTED

*THE object of derived class is only created that’s why the object of the base class
cannot be created thats why it is known as Abstract Class

*constructors and destructors of the base class cannot be inherited

Class number

{
Int no1;

Public:

Int no2,no3;

Protected:

Int no4;

};

Class product:public number

{ /*public-int no2,no3

*protected –int no4

Int p;

};

Dara type size

Int 2 bytes

Short 2bytes

Long 4bytes

Char 1byte

Char nm[25] 25bytes

Float 4bytes

Double 8bytes

LONG DOUBLE 10 BYTES

Potrebbero piacerti anche