Need for inheritance:
one basic reason behind this is the
the capability to express the
inheritance relationship.
Another reason is the idea of
reusability
one reason is transitive nature of
of inheritance
inheritance:
some time we need to repeat the code
or we need to repeat the whole class
properties. So it helps in various ways
it saves memory space
it saves time
it will remove frustration
it increase reliability of the code
it saves the developing and testing
efforts
Why we use inheritance?
To increase the reusability of the
the code and to make future usable
usable for another classes.
we use the concept of inheritance
How inheritance can be
achieved?
In the inheritance there will be a
a parent child relationship. There is
There is a class called in which all
all the properties are defined and
and generally, it is refered as a
base class. There is also another
another class in which is derived
derived from the existing one are
are known as a derived class.
Inheritance Access Specifiers
Public Inheritance
This inheritance mode is used
mostly. In this the protected
member of Base class becomes
protected members of Derived class
class and public becomes public.
Inheritance Access Specifiers
Protected Inheritance
In protected mode, the public and
and protected members of Base
class becomes protected members
members of Derived class.
class B : protected A
class C : protected B
Inheritance Access Specifiers
Private Inheritance
In private mode the public and
protected members of Base class
class become private members of
of Derived class.
class B : private A
class C : private B
Types of inheritance
There are different types of inheritance
inheritance
single inheritance
Multiple inheritance
Hierarchical inheritance
multilevel inheritance
hybrid inheritance
Single inheritance enables a
derived class to inherit properties
properties and behavior from a
single parent class. It allows a
derived class to inherit the
properties and behavior of a base
base class, thus enabling code
reusability as well as adding new
new features to the existing code.
code.
syntax
class A
{
-------
-------
};
class D : access specifier A
{
-------
-------
};
Derived class
In Inheritance you create new
classes from existing class. Any
new class that you create from an
an existing class is called derived
derived class.
Base class
existing class is called base class.
class.
SOURCE CODE
OUTPUT:
POSITION=0
POSITION=1
POSITION=0
Final presentation programming

Final presentation programming

  • 6.
    Need for inheritance: onebasic reason behind this is the the capability to express the inheritance relationship. Another reason is the idea of reusability one reason is transitive nature of of inheritance
  • 7.
    inheritance: some time weneed to repeat the code or we need to repeat the whole class properties. So it helps in various ways it saves memory space it saves time it will remove frustration it increase reliability of the code it saves the developing and testing efforts
  • 8.
    Why we useinheritance? To increase the reusability of the the code and to make future usable usable for another classes. we use the concept of inheritance
  • 9.
    How inheritance canbe achieved? In the inheritance there will be a a parent child relationship. There is There is a class called in which all all the properties are defined and and generally, it is refered as a base class. There is also another another class in which is derived derived from the existing one are are known as a derived class.
  • 10.
    Inheritance Access Specifiers PublicInheritance This inheritance mode is used mostly. In this the protected member of Base class becomes protected members of Derived class class and public becomes public.
  • 11.
    Inheritance Access Specifiers ProtectedInheritance In protected mode, the public and and protected members of Base class becomes protected members members of Derived class. class B : protected A class C : protected B
  • 12.
    Inheritance Access Specifiers PrivateInheritance In private mode the public and protected members of Base class class become private members of of Derived class. class B : private A class C : private B
  • 13.
    Types of inheritance Thereare different types of inheritance inheritance single inheritance Multiple inheritance Hierarchical inheritance multilevel inheritance hybrid inheritance
  • 14.
    Single inheritance enablesa derived class to inherit properties properties and behavior from a single parent class. It allows a derived class to inherit the properties and behavior of a base base class, thus enabling code reusability as well as adding new new features to the existing code. code.
  • 15.
    syntax class A { ------- ------- }; class D: access specifier A { ------- ------- };
  • 17.
    Derived class In Inheritanceyou create new classes from existing class. Any new class that you create from an an existing class is called derived derived class. Base class existing class is called base class. class.
  • 18.
  • 21.