click the Bell icon to get latest videos
from Ekeeda Hello Friends in this video
we will study a new topic called as
Inheritance as we have already studied
Inheritance is an important feature of
object-oriented programming now let us
study how to implement the Inheritance
and how to write a program using
Inheritance inheritance stands for
derivation it means what the mechanism
of creating the new class from already
existing class is called as Inheritance
now let us take an example suppose if I
have already written a program in which
I am performing incrementation operator
it means suppose if Im incrementing the
value of variable by one after some time
suppose if I realized you know I want to
decrement the value of variable by one
also then in that case I have two
options either I will write a new
program or I will modify the existing
program now when I write a new program
the writing a new program will be very
time consuming and modifying the
existing program means what again we
have to recompile the program again we
have to find out the errors and so on so
what I will do I will find out the
intermediate way in between this so I
won't write a new program or I will not
modify the existing program instead I
will create a program which is a child
program of my previous program now since
we are using the classes in terms of
object-oriented programming
let us not use a term called s program
so I will use a term called s class so
it means suppose if I have already
written a class which is performing
incrementation operator and now if I am
in need of a class which will perform a
decrement ation operator then I will
perform work I will create a class with
and that class will be a child of my
existing class then this entire thing in
this entire scenario is called as what
inheritance in the advantage of using
inheritance is what when you create a
child class of parent class
your child class can inherit all the
features of your parent class your child
class can use all the variables which
are there in the parent class so this is
the main use of what inheritance for an
example suppose class increment is
incrementing the value of variable by
one then I will create one more class
class decrement which will decrement the
value of variable by one so in that case
I won't declare any new variable in
clastic remain I will be using the
existing variables which are already
there in what class increment so this
concept is called as what inheritance
now when it comes to inheritance there
are various types of inheritance single
inheritance multiple inheritance
multi-level inheritance hierarchical
inheritance and hybrid inheritance now
we will study each and every inheritance
in detail with the help of some example
but as of now first we will summarize
our definition of inheritance
inheritance is a mechanism of creating
the new class based on what my old class
when I create a new class I called it as
derived class whereas my old class is
called as base class or you can call it
as what parent class and my new class I
can call it as what child class so
inheritance allows us to implement the
concept of whatever usability I will be
already having my old class and my new
class will inherit all the features of
what my old class so now see let us see
the definition of what each and every
type of inheritance number one is called
as single inheritance a derived class
with a single base class then I called
it as single inheritance for an example
see here I is my base class and B is my
derived class so derived class with only
one base class is called as what single
inheritance quality well it he returns a
derived class with several base classes
is called as multiple inheritance in the
multiple inheritance you will be having
more than one base class and only
derived class so this is the diagram of
what multiple inheritance here I have
multiple base classes whereas only
single derived class then the next is
called as hierarchical inheritance
hierarchical inheritance is just
opposite of multiple inheritance in the
hierarchical inheritance there will only
be one base class and multiple derived
classes so it means what a base class
with several derived classes is called
as hierarchical inheritance multi-level
inheritance now in the multi-level
inheritance we create a derived class
and that derived class is created from
already existing derived class I will be
calling it as multi-level inheritance
for an example say this diagram in this
diagram this is my base class this is my
derived class so I will create a new
derived class based on my existing
derived class then I will call it as
what multi-level inheritance now
multi-level inheritance you can relate
this inheritance with the help of what
father grandfather and child
relationship so I can call it as base
classes my grandfather where as this
intermediate derived class is my father
and the new derived class is called as
child so this is called as multi-level
inheritance then the last is called as
hybrid inheritance in the hybrid
inheritance it involves more than one
inheritances into it so whenever in the
program if you have more than one
inheritances into it then i called it as
hybrid inheritance so let us summarize
the things again so let us summarize the
things again mechanism of creating the
new class from already existing class is
called as inheritance in the inheritance
my old class is called as base class
whereas my new class is called as
derived class then we studied various
types of inheritance --is that is single
inheritance multiple inheritance
multi-level inheritance hierarchical
inheritance and hybrid inheritance that
is syntax of inheritance now let us jump
on to the next topic that is syntax of
inheritance now see this is the syntax
of inheritance first
I use a keyword called as class
then I write a derived class name then :
disability mode and my base class name
this is class now say this is an example
of single inheritance now we have
already studied single inheritance means
what there will be only one base class
and one derived class in this class I
have created a class called as index and
in the protected but I have declared a
variable called as count then I have two
constructor over here in the first
constructor is called as 0 argument
constructor the kafirs constructor is
called as 0 argument constructor where I
have initialized the value of variable
count as 0 then the next constructor is
called as 1 argument constructor where I
have initialized the value of count is
equal to C then I am displaying the
value of count and then I have created
one more function whose name is operator
plus plus now see if you will see this
function you will understand operator
plus plus means what here I am
overloading my plus plus operator so
count plus plus means what here counter
value will get incremented by 1 then now
see this is very important thing here I
have created a derived class whose name
is index 1 now this derived class is a
children of my class index so follow let
us follow the syntax of derived class
first I write class is a keyword then my
derived class name which is index 1 then
colon
then my visibility more visibility mode
is a public and then my base class name
which is it makes now in the index 1
what I am doing Vikram ending my
operator
I am decrementing my variable K value by
1 so public void operator minus - oh
yeah Here I am overloading my - -
operator count - - so it will decrement
the value of count by 1 then this is my
main function now if one more thing in
the main function when we create a
object here object you will create an
object of OT a derived class not a base
class so here my derived class is index
1 and I is an object of what we write
class
I plus blessed so it means what I'm
calling operator plus plus function so
it means it will increment the value of
your count by one and so when I write I
dot displayed it will call a function
display so it means what it will print
the value of count then again I am
invoking operator minus minus function
so that's why I minus minus so your
operator minus minus function will get
called and I dot display means what we
are called cabal you will get
decremented by 1 so this is how I write
a program of single inheritance I
created a class whose name is index then
I declared some variable and then in the
public section I have created two
constructor the first constructor is a 0
argument constructor whereas the second
constructor is a 1 argument constructor
now one more thing here I would like to
discuss that is use of protected keyword
now see in the previous examples we have
seen a private keyword now what is the
mean of private and what is the mean of
public that we have already studied
private means what the whatever we write
inside the private keyword those members
will be a strictly a member of only
class so it means the members or the
functions who are not a part of class
they cannot access those variable but
when I write protected it means what now
see here I am creating what inheritance
or inheritance made I will be creating a
derived class and that derived class
will be a children of your parent class
so obviously yet derived class will
inherit all the features of your parent
class so it means you need protected
access protected access means what when
I give a protected access the variables
are the members which are there in the
protected those members are accessible
to the derived class but they are not
accessible to any other class or any
other function so when I write a private
the visibility vote is restricted only
within the class but when I write a
protected the visibility mode is not
restricted only within a class but it
will allow you it will allow the access
to the derived class also but no other
class other than a derived class can use
those members which are
in a protected keyword so that is
basically use of what protected keyword
then in the public section whatever you
that we have already discussed we have
to created two constructor zero argument
constructor and one argument constructor
and then I created a derived class whose
name is index 1 and that derived class
is a children of what your class index
tao-tsay
point to be noted here that is I haven't
declared a count variable again in the
derived class it means what my variable
was already declared inside the base
class so derived class can directly
access the variable which is there in
the base class that is the use of what
inheritance inheritance allows the
derived class to access all the members
are all the features of base class
thanks for watching this video
in the next video we will study the next
type of inheritance that is multiple and
multi-level inheritance --is for the
latest video please subscribe each RL
equal ah
you
