So I welcome you again to the next session on Happy Learning, and we are going to cover inheritance
in C++, that's the topic we are covering on this unit.
So let's jump on to that topic.
So talking about inheritance, inheritance means the capability of a class to derive the properties
and characteristics from another class.
So suppose we have two classes classes a class and Class B OK, and Class B want to get some properties
from Class A. That is normative so that properties can be their members or even member functions.
So why we are using an inheritance?
Inheritance is one of the most important feature in the C++ order in the world of object oriented programming.
But why we are using inheritance is to enhance that using feature.
So instead of writing everything from scratch, which is already defined in this program, if we can
reuse the existing components and create new components from those existing components, that will be
more equally vital in order to promote that.
In order to make sure that you can reuse all the components, all the glasses, all the objects, all
the functions are all that values are data variables.
In a program, we can use the feature called inheritance that is too important garden type you need
to know while we are talking about inheritance in C++ learning.
Superclass OK, and none of this subclass.
So a subclass is a class that inheritance inherit properties from another class.
So suppose there is a class card, Class E and Class another class card, Class B and Glass B's.
Inheriting some properties from Class A, then Class B is called the subclass of class, so top class
is also called deriving a class, then next class superclass.
Suppose that is a class which is a reference class for a sub class.
That means that our subclass is inheriting some functions and variables from other superclass.
So that class is called superclass.
So we can see a good example of inheritance all here.
Bensouda, the case of three makers.
OK, I have three acres, so I have created three classes for these three vehicles and each class contained
its own member functions.
But I know very similar aspect, right?
It's a class guard.
Bess and B+ Best will contain function to calculate that amount regard to Philadelphia.
So that is a full on function capacity function to get how much fuel that particular vehicle can hold,
and they decided the function.
We just can't apply brakes, which will specify the amount of effort or effort required to apply the
brakes.
So even if it is three different classes, these three vehicles can use these functions right.
See Class Bess have all these three facilities.
Similarly, Blast God should also help you out of my own capacity and apply brakes because this is common
to all the classes and also class.
Even if it is a trap, it should be able to find the amount of fuel required, capacity required and
how much I would be required to apply the brakes.
So all these classes require these three functions.
So instead of making this class, each class a new function for the same purpose, so the buses are
safe, right?
So instead of making three three different functions on each class, we can be sure that we create a
new class car class maker.
So that class very good contains all these three functions.
So here you can see that if you allow more designer capacities that apply brakes is there, and what
happens is class best car and truck can get this function from glass very good and use it whenever required.
So instead of writing the same functions three times in each of these class, I have created a separate
super class which is having all these functions and all subclasses or derived classes.
Best Scott and Truck gets the functions when nobody forms to use.
So here you can see an inheritance diagonal class.
Meg Lees, the superclass and Buska and Track are that subclasses and the adding head hitting see that
this is getting see that this is getting this function from the Ebo class.
These three Genzel class buses inheriting B-Class vehicles.
So this is that diagonal.
So what I who is that superclass that will be on the top and the subclass will be on the bottom?
And yeah, auto will be like this subclasses inheriting the superclass.
So there should be an arrow from superclass to stop fastener drums up class to class, but instead we
will be putting an arrow from superclass to subclass how that's how you would an inheritance bag.
So how you can implement inheritance in C++ is our next topic, and there is a specific syntax dedicated
for implementing inheritance in C++, so.
Here is the syntax I have given for you, so class during this class, then you have to give this up
class name.
Then you have to put this dodge symbol up and down dog, and then you have to put the access mark,
then base class name.
So you have three access Marzia, Public Protector and private and you getting heritage superclass in
three ways that is Public Protector and private each have a different speciality so that we will be
discussing shortly.
So after you write this index, we will be writing the body of the class and inside that basis, followed
by a semicolon.
So you have if supposing I want to inherit a class guard Class B.