The mechanism of deriving a
new class from an old one is
called inheritance or derivation.
Definition of Inheritance:
Inheritance is the mechanism
which allows a class A to
inherit properties of a class B.
By Hardeep Singh
Single inheritance
Multiple inheritance
A
C
By Hardeep Singh
Hierachical Inheritance:
A
B
Multilevel Inheritance:
A
B
C
By Hardeep Singh
Hybrid Inheritance:
A
C
D
By Hardeep Singh
The major advantage is the reusability. Once
a base class is written and debugged,it need
not be touched again,but can be used to work
in different.
It also reduces the frustration in complex
programming.
Reusing exiting code saves time.
By Hardeep Singh
The larger the inheritance model gets, the
wider the mapped table table gets, in that
for every field in the entire inheritance
hiearchy, a column must exit in the mapped
table.
By Hardeep Singh
Public:
Exp: class A
{
Public:
Int x;
Private:
Int y;
};
Class B : public A
{
Private:
Int p;
}
By Hardeep Singh
Base class
Derived class visibility
Visibility
Public derivation
Private derivation
Protected
Private
Not inherited
Not inherited
Not inherited
Public
Public
Private
protected
protected
protected
private
Protected
By Hardeep Singh
Exp:class a
{
Private:
Int x;
Public:
Int y; };
Class B : private A
{
Int p; };
By Hardeep Singh
Exp:
Class A : protected B
{
Private : int X;
};
By Hardeep Singh
An abstract class is one that is not used to
create [Link] abstract class is used only
for base class.
By Hardeep Singh