Hello everyone.
So in the last session we discussed what is different decks for using inheritance.
I hope that part is clear.
Now let's see the code
so outline number 28.
I am creating the object of the correctness.
Okay so what will happen.
So this is our weekly class and these are some of the properties.
So at this land line number 28 what will happen.
Default construct of the class will be called which will initialize the properties of difficult class.
No doubt.
Now line number twenty three I'm creating the object of got class.
Now God is a special class white especially because it innate from difficult class.
Okay so this is our card class and inside the god class we have some part of difficult class and some
god specific properties.
So the parties we have color and we have them ties.
The third property which is the Mexican property will not be inherited.
Okay so for creating the object of the Card class we have to create this vehicle class for creating
kind of class object.
Okay.
So before greeting card class object we have to create this vehicle class object.
So we have to initialize all those properties that are accessible to the car.
Class Okay so when we write Ghazi so as soon as as soon as we create this kind of class object then
first of all the color class constructed will be called okay.
It will be called automatically it will be implicitly called okay.
And then the guide class may be called Okay so via the victim class will be called first because first
we have to create this part then only we can create this outer block in the memory okay.
So when we write Ghazi see what will happen first the vehicle class constructor will be called so that
we can initialize.
We can create this part in the memory then that kind of constructor will be called so that we can create
this outer block in the memory.
Okay.
So what do we the order of calling constructor in case of inheritance.
So what will be the order of calling a strict linkage of inheritance.
Suppose we have three classes Glass a class we inherited from Class A and glossy inherited from Class
B.
So if I create an object of Class E E then what will happen.
Only the E class constructor will be called.
Okay so this is a and it has some properties so only the E Class constructively because called no doubt.
Now if I create the object of Class B then what will happen.
So this is destructive for Class B it contains e and some B specific properties then first of all what
will happen.
Constructor it will be called and then construct the B will be called.
Okay so first a class constructed with regard then because constructively with class because first we
have to create this part then we can create the outer part.
Okay.
Now if I create the object of C class then what will happen.
First of all this is the structure of class C it contains B and some C specific properties and B contains
a and b specific properties.
So first of all we have to create a So E class constructor will be called.
Then we have to create B.
So this B class constructor will be called and at last.
This C class constructed will be called.
Okay so I hope that you now understand the order of calling constructors in case of inheritance.
Okay now let us verify our statement.
So let's in
Okay so let's make some constructors so I am creating a default constructor.
Okay so default we could construct that and now inside the constructor let's create something see out
the default construct that
and now let us also create the default their default destructor for vehicle class.
Okay so a special symbol and vehicle the go district.
Okay
and now let's do the same for God.
Class also Okay so we will create the god class default constructor and district in constructor.
Okay.
So God now let us bring something C out.
Car default constructed
and now let us all to create the destructor.
Okay
okay so we have because class default constructed and destructor similarly called class or default constructor
and destructor okay.
Now what will happen.
So add this line what will happen.
So v class default constructor will be called.
Okay so we call class default constructor will be called and add this line.
Gotta see what will happen first the vacate class default construct that will be called and then the
car.
Class default constructor will be called.
Okay now let's run this file to see the output.
Now let's come and everything out
okay so we call V and Ghazi.
Now let's add this file
okay.
Now let us try to analyze what is the output.
So first the vocal class constructor will be called.
Now this construct based being called for creating the VK class object.
Okay so this first output is due to be called class.
Now the second output is we are creating the called Class object.
So first the vehicle default constructor will be called then called constructor will recall.
Okay so the first line is do you do the class.
Now the next two line are due to Card class and the order for District is just opposite the order of
the inheritance.
So first the card destructively McCall then the school district.
So these are due to go out of class.
And the last line it is due to the class.
Okay so the order of district Burke called is just the opposite of the inheritance.
Okay so the first line this is due to class the next to line.
This is due to card class.
Again the next two line are due to card class destructor.
And the last line is due to the class destructor.
Okay so the order for District based oppose it off the order of the inheritance.
Okay.
Now what is happening here is
so had this line implicitly what happens is it is something like this so we have started about initialization
list.
So what is happening here is when we are writing code to see what will happen it will call its default
constructor.
So when we will reach this default construct but it is implicitly something like this initialization
list.
Okay.
So what will happen.
What is the use of initialization list.
So before entering this constructor before reaching line number 29 we will go to the vehicle construct.
Okay so that's why this code is getting printed first.
This called the default construct is getting printed first.
Okay so okay so implicitly this is something like this but you do not need to write this here because
the vehicle class default construct it is called implicitly okay.
This call automatically so we don't need to write this.
Okay.
Now what will happen if I create a better mid priced vehicle constructor.
Okay so we have a better motorized vehicle constructor it takes an argument Lex's ID and what it does
is Max speed is Z.
Okay.
So what will happen now.
Okay so what happened is so when we write Ghazi what will happen.
It will call their default constructor of the vehicle class.
Okay.
So always the default constructed will be called automatically.
Okay but if we want to call the betterment based construct of the vehicle class then we have to call
explicitly okay.
I'm repeating myself when we write Ghazi what it will do.
It will call the default constructor of the vehicle class.
But now what I want is I have a better memorized constructor parameter traced the call constructor and
I want to call this better my place constructor I want to call this better taste construct better.
So what we have to do we have to call explicitly
and this is implicitly we don't need to write anything.
This will recall implicitly but for calling the paramedics constructor we have to call explicitly.
So what is this index so in Texas very simple we will write God C then with the help of initialization
list we call.
And since it takes only one argument so we will give one argument okay.
And that's all okay.
So this is just an index for calling the betterment days constructed.
Okay.
And for default construct this index is very simple Ghazi and simple we call okay.
But in case of default we do not need to write this.
Okay now let us call the param at base constructor so I want to call this better my test constructor.
So I have to pass a value let's say 5.
Okay.
Now this is correct.
Okay print something so that we can verify.
So we'll see out we call barometer based constructor
okay.
So now let us comment out everything.
So to avoid any confusion.
So we have only got to see here.
Now we will try to analyse for boolean output so Ghazi see will.
We will reach here Ghazi and in the initialization list we are calling the better metrics constructor
of the weekly class.
So we will reach here.
So the output will be we call a paramedic based constructor and then got a default constructor.
Okay.
So this will be our output.
And then the order of district pay is just the opposite of the order of inheritance.
Okay.
So now let us turn our file
okay so we can see here is we call paramedics construct a card then card default construct a card and
our district pays deposit first.
The car will be destroyed and then the vehicle will be destroyed okay.
So everything is running fine okay.
So now let's take more examples.
Okay.
So okay let's remove this
and now let us also commend the vehicle default constructor.
Okay
so I'm commenting out we a default constructor.
Okay.
So now their default construct of the vehicle class is not visible since we have created our own betterment
based construct.
Okay.
I'm repeating myself since we have created our own betterment based construct that the vehicle.
Class default construct is not visible to us any.
Now what will happen.
Can we create our class object now.
So will this line work.
Ghazi will it work on artwork so the output is it will not work.
Okay.
So let us in this file so we will get an added.
And now let us try to analyze what is the advice you are getting an added.
Okay
so when we write Ghazi what it will do.
It will try to call the default constructor of the because class and their default construct of the
vehicle class is not there because we have created our own parameters constructor.
So this line is wrong.
This line will throw us at it.
So we cannot create objects of the car class.
No.
Okay so what we have to do.
So here we have a compulsion.
Okay.
So now in order to create a guide class object there is a compulsion now that we have to call the parametric
constructor or difficult class because the default one is not visible.
Okay.
So here we have a compulsion in order to create the object of the second class.
We have to call the paramedics constructor or difficult class because the default construct of difficult
classes not there.
Okay.
Now disconnect correct if you will render a file you will not get any added.
Okay so our code is working without any errors.
Okay.
Now this is not the right way.
So what is the right way.
So that I ways first we will take the input and then we will pass the X here.
Okay.
So this is the right way.
Now if you will write Ghazi we have to change this also because Ghazi will call the default constructor
and we do not have default constructor we have better my taste this is now a paramedic's constructor.
So let us change
okay so we cannot create objects like this because we do not have a default constructor because we we
have created our own parameters constructor.
So in order to create the object we have to pass a value we have to call paramedics constructor.
Okay now let's on this file
okay so everything is working fine.
Okay.
Also no let us try to analyze the output.
So first the vehicle class better my desk constructor will be called then God better my test constructively
be called and then the order of District based deposit.
Okay okay.
So now let us take one more example so now let us create another class Gaussian density okay.
So this class from the city let us and headed this class in that it's from the court class.
Okay now let us also create its gastric band destructor okay
city constructed
unnecessary.
The forward concept is better.
Okay so let's leave it you deconstruct only and it will also create or unnecessary destructor
okay.
So now we have T levels of inheritance.
No.
Okay
so what we have is we have this little glass God glass inherits from the victim glass and there are
only 30 glass inherits from the car glass.
Okay so three levels of inheritance is there.
No.
Okay.
So when we create the audacity object.
So if I write
letter at the edge then what will happen.
First of all it will call.
So what will be the order of inheritance.
Okay.
So first the victim class object will be called the class will be called then the car class construct
that will be called and then the university construct that will be called.
So this will be the order.
Now what will happen when we write this object on the city edge what it will do.
It will reach here.
Line number 48 and implicitly what will happen.
Got a class default constructor will be called.
Okay.
So we will call God class default constructor and God class default constructor is not visible to us.
Why.
Because we have created betterment based constructor so we will get an added.
Okay so this line will throw at it why it will throw at it because the car class default constructor
will be called and the car class default constructor is not there.
Okay let's see dieted Okay so let's come and out everything.
So we are creating an object of unnecessary.
So what it will do we will reach this line for dessert.
It will call the car last default constructor and the Goddard class default construct based not there.
Right.
We call car class default constructor because implicitly default constructor is called.
Okay.
So we will get an idea.
Okay.
So we are getting an added now in order to resolve this error.
What we have to do since we only have better my constructor.
So we have to call this better my test constructor.
Now there is a compulsion here we have to use the initialization list.
So God 5 in order to call the paramedics constructor.
Okay so now it will work.
Okay now we have to explicitly call paramedics constructor.
Now let's add in this file
okay so what is happening here is this is daughter first that we could last better my test constructor
then guided by my place constructor and the whole city construct and the order of District based deposit.
Okay so everything is running fine now if I want to pass parameters.
Suppose I want to pass barometers so God and anyway so X will go to the victim class and for Y what
we are planning to use here is the let's say number of gears
number of gears is Y Okay.
Now what will happen here is since the car class is now taking two arguments has input.
So let's see this is ridiculous.
It takes two arguments x and y okay because the car class constructor takes two arguments so we'll pass
X and we will pass Y Okay.
Now for creating the horn that's the object we cannot create object like this because it will call the
default concept then default construct is not dead because it's a paramedic's constructor No.
Okay so we have to call better my test constructor we have to pass two values use every possible values
lecture two values that four and five okay.
So what will happen better my desk and said I will be called.
So it will reach here X and Y will be passed to the god class parameters constructor.
So a number of games that way and it will pass x.
So from here we will reach the vehicle class and first of all because last better make this constructor
called then God class Parramatta's constructor called and then the homeless you deconstruct the code
so this will be our output.
Okay next on this file
okay.
So first of all we get class paramedic's constructor then God and then horn deputy and the District
based just the opposite.
Okay so when lasting so one last thing is.
So we have this weekly class called Class in added from the working class and the whole industry to
cut down this class inherits from the car class.
Okay.
So a class can only call the constructor of its immediate parent.
Okay.
A class can only call the constructor of its immediate appearance.
So this is right.
And this is wrong okay our class can only call the concept of its immediate parent.
Okay.
Similarly our class can call the construct of the working class but don't assume the class cannot call
the constructor of the working class.
Okay so that's all from my side.
Thank you.