What Is Inheritance?
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.
Types Of Inheritance
Single inheritance
Multiple inheritance
Hierachical Inheritance
Multilevel Inheritance
Hybrid Inheritance
Advantages Of Inheritance
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.
Disdvantages Of Inheritance
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.
Private, Public, Protected:
Public:
Exp: class A
{
Public:
Int x;
Private:
Int y;
};
Class B : public A
{
Private:
Int p;
}
Base class Derived class visibility
Visibility- Private Public Protected
Public derivation-Not Inherited Public Protected
Private derivation-Not Inherited Private Private
Protected- Not Inherited Protected Protected
Private Inheritance:Exp:class a
{
Private:
Int x;
Public:
Int y; };
Class B : private A
{
Int p; };
Protected:
Exp:
Class A : protected B
{
Private : int X;
}
Abstract Class
An abstract class is one that is not used to
create objects.an abstract class is used only
for base class.