2. DEFINITION:-
• It is a very important concept of object
oriented language.
• It is the process of deriving a new class
for an old existing class.
• In other words we can say that it is a
process of passing the properties of one
class to another.
4. • Base class:- A class whose properties are been
inherited by another class is knowns as base class,
super class or parent class.
• Derived class:- A class which inherit the
properties from the base class is known as derived
class, sub class or child class.
• Intermediate base class:- It is a class which is
derived but at the same time it is also a base class.
BASE CLASS
INTERMEDIATE
BASE CLASS
DERIVED
CLASS
5. CLASS X
{
A---------;
B---------;
C---------;
};
CLASS Y:PUBLIC X
{
A---------;
B---------;
C---------;
D---------;
E---------;
};
CLASS Z:PUBLIC Y
{
A---------;
B---------;
C---------;
D---------;
E---------;
F---------;
G---------;
};
EXAMPLE OF INHERITANCE :-
6. Derivation Labels/Modes:-
• Public:- When the base class is inherited to the
derived class the public members of base class will
become the public members and the protected members
will become protected of the derive class.
• Private:- When the base class is inherited to the
derived class the public and protected members of base
class will become the private members of derive class.
• Protected:- When the base class is inherited to
derived class the public and protected members of base
class will become the protected members of derived
class.
7. Example:-
Class base
{
Private:
int x;
Public:
int y;
Protected:
int z;
};
Class
derv:private
base
{
Private:
int y;
Private:
int z;
};
Class
derv:protecte
d base
{
Protected:
int y;
protected:
int z;
};
Class
derv:public
base
{
Public:
int y;
Protected:
int z;
};