Hello everyone.
So in the last video we started discussing about inheritance.
I hope that is cleared.
So so what we have is.
So we discussed we have a working class and we have a class.
God got a class will inherit from the working class.
So we call the killer class as base class or parent class.
OK.
Basic class or parent class.
And we will call the class God as they drive the class
or change the class.
OK so in this video we will learn about ordinary dance and tics.
OK.
So let's start
so we have a class vehicle.
So this class vehicle has three properties max speed number of tires and Collette property.
So the max built property is private number of days properties protected property and declared property
is the public property.
OK.
So
so since the killer property is a public property it can be used anywhere inside or outside the class.
OK.
So number of nice properties are protected properties.
So it can only be used in the derived class.
It can be used inside the vicar class.
And if we want to use the protected property outside the class then it will be used only in the derived
classes of the because last.
And since that makes properties private property so it cannot be used outside the class.
It can only be used inside the victim's class only.
Okay.
So now what we will do we will create a class God the class Colville inherited from the victim class.
Okay.
So what will happen.
So virtualize index so first you will write the keyword class then the name of the class which is God
then column.
Then we will write access specified.
Now this access specified can be public private and protected then the name of the class which you want
to inherit so many of the classes we call.
And that's all.
So this is this index for inheritance.
Okay.
So the value of x is specified.
It can be private.
It can be public and it can be protected.
Okay.
So what is the meaning of access specified.
So it will specify how we will be able to access the properties of the base class.
Okay.
It specifies how we will be able to access the properties of the base class.
Okay so let's see in good
So class car column then the access specify let's say the access specified is public.
We will see private and protected also but for now let's say the Express divide is public.
And the name of the class which is we call.
Okay.
So what will happen if I had if I write this much code.
So what I'm having it is
so when I write this plane line number 16 what will happen.
So I have this class so call class and I have another class so these classes got.
Okay.
So I have some private properties I have some public properties and I have some protected properties.
And what I'm doing at line number 16 the access specified is public.
So we are inheriting publicly okay.
Class car is being inherited publicly.
So what will happen.
So private properties that cannot be used outside the class.
So they cannot inherit we cannot inherit private properties because we cannot use them outside the class.
So what will happen to the public properties.
So the public properties will become the public properties of the Car class.
Similarly the protected properties will become the protected properties of the car class.
Okay.
So at this moment where do the structure of the car class so
the structure of the car class is something like this.
This is called class.
So inside the private we have nothing.
Okay.
So inside the protected field inside the predicted members we have only one member which is named Dias
because of inheritance so pretty ridiculous.
And I'm Dias and inside the public properties we have string colored.
Okay.
So we have color.
So this is the structure of guide class.
Okay.
After line number 16 this will be the structure of the kind of class.
Okay.
So once again private properties never inherited because they cannot be used outside the class public
properties will become public members.
And similarly the protected members will become the protected members of the court class.
Okay.
So this is the case when we are inheriting publicly okay.
So this is the result of inheritance now car class can also have its own properties.
Okay so let's include So let's say car class has some public properties of its own.
And let's say the name of the properties number of girls.
Okay so name gives
okay.
Now let us know what will happen at this lane what if this scenario at this lane so
this is guy glass private.
We do not have anything inside the protected.
We have one property which is number of tires so numb tires and inside the public we have two properties
now.
So one is to do inheritance which is color.
So this is due to inheritance.
And the second property is the property of Decatur Plaza.
So it is a number of gears Nam gives okay.
So although we can see only when properties although we can see only one property inside the car glass.
But actually we have three properties.
Number of tires color and name gives okay.
So let's say the print function.
Okay
so let's say the print function white paint.
Now inside the print function let us try to print the value of number of days.
So see out
so line number two in doing this correct.
Man class car property has the property number of days.
Okay.
So let me first write everything.
We will see what Debra.
What are the properties that we have.
And what are the properties that we don't have
let us try to print colored
and let us try to print the number of gifts
also let us try to print max speed.
So see owed
max speed
OK.
So what is the scenario
so we have a glass car
so inside the glass got inside the private properties.
We don't have anything for predicted.
We have a number of tires due to inheritance due to inheritance.
Publicly we are inheriting publicly this whole number of tires and inside the public.
We have two properties.
One is due to inheritance which is color.
And the second one is the property of the Aquatic class which is number of games name games.
Okay.
So this line is great.
We can access number of tires.
Why.
Because number of diocese a protected property and predicted property can be used inside derived class.
So it is correct color we can access color because it's a public property we can access number of gays
because it's a public property can be accessed mixed speed.
No we cannot access max speed because class car does not have any max speed property.
Okay.
So if you will win this fight we will get an edit for max speed.
Okay.
So let's see let's try to run this file so we will get an added max speed.
Let's see what is there at
so we can see max speed is private.
OK.
So inside the print function we are getting that ad that max speed is private.
Basically it will not be inherited.
So the class got Robert it doesn't have any property max speed.
Okay.
So what is what is happening now.
It is.
So when we do when the car class in that it's publicly when the access specified is public what will
happen.
So the public properties of the vehicles class will become the public properties of the car class.
Okay.
The protected properties of the vehicle.
Class are now also that protected properties of Decatur class and the private properties since they
cannot be used outside the class.
So private properties does not participate in inheritance.
Okay.
So this is the scenario.
Okay.
So let's try to create some object of the class and let's see
so this this line is this line will not work.
This is wrong.
Now let's turn this file so this time our code is running no
so let's create some objects of the week in class.
So we call we.
So can we access the killer property without color let's say the color is blue
Can we access the max speed property let's say we dart max speed as food and we dart number of tires
as let's say again forward.
Okay so if we will win this fight will we get any of it.
So let's try to understand
so we have a class we call so and say that because lives in the private properties what we have we have
max speed
for the protected property we have number of tyres num tires
and inside the public we have only one property which is called Okay so we don't collide goes blue.
This is right because the color is public color is public.
So this is right.
We dot max speed this.
Is this right or wrong this is wrong because max speed is a private property.
It can only be used inside the vehicle class.
Okay.
Number of days.
So this is a protected property.
Number of days that predicted property and protected property can be used inside the vehicle class.
And if we want to use number of tires outside the vehicle class then it can only be used inside.
Did it have the classes.
So we can reduce it inside the mean.
Okay.
So line number 30 and line number 31 both are wrong.
So we will get at it if we we're in this file.
Okay uh let's see
so this time we will get to errors for the max speed and for the number of tires
so the error is first that is due to max speed because the max rate properties private and the second
that is due to number of times because it is protected.
Okay.
And protected property can be used inside the derived classes
so let's make let's come and get out
now let us create the object of a class.
So Ghazi let us try to understand the killer property so the killer property is deep public property
so we can access it.
Let's say the killer is black
so can we exist the number of times property no dice property
so let's say the number of dice is food.
So can we accept a number of nice property number of tax properties the protected property.
Let's see in some time and let's say the number of givers
the number of gears are five okay.
So what will happen if a million this file
so the structure of God class is very simply inside the private we don't have anything.
And inside the protected property we have one property you do inheritance and that property is named
Dias and inside the public.
We have two properties.
One is to do inheritance which is collect.
And second is the property of the kind of class which is named gives Okay so we can access color because
it's public we can access numbers because it is also public.
But can we exist.
Number of days it is a protected property and protected property can be used inside their derived class.
And we are using it inside the mean.
Okay.
So line number type 5 this line will throw us at it.
Okay.
This line will throw us.
Let's see
so if you see we will get at it number of days property is a protected property.
Okay.
See the line number 35.
Edit within the statement number of diocese protected property.
Okay.
Now let's come and doubt out okay now let's send this file so our file is running without any added
okay.
So
so we have this property card God we have this glass God
private is empty protected member is only one which is name Dias and public it has two properties color
and the second one is numb gives
okay.
So what will happen if I inherit God.
Plus publicly let's say I have a glass horn pretty so this is an absolutely glass and steel glass is
it inheriting God or glass publicly.
So what is the role for publicly.
First of all private properties do not participate in inheritance.
So private will be empty.
Okay.
And since we are inheriting publicly what will happen protectorate will become protected so protected
property.
It will contain them dies and public will become public so public have two properties color and name
gives
okay.
So this is the case when the home that's ridiculous is inheriting the god class publicly.
Okay.
We have two more access specified.
So in this case the in Texas glass Honda glass on density
public access specify.
And God.
Okay so we can use private and protected here also.
Okay we have three access specified public private and protected.
We have seen the code for public.
No let us try to understand what will happen in the case of protected and private okay.
So
okay so this is our biggest loss and this is kind of close.
And this is because glass and this is kind of glass okay so we have private.
We have protected and we have public.
Okay.
So if the car glass if the vehicle glass if we inherit the vehicle glass protected using the excess
specified predicted what will happen.
So first of all private properties do not participate in inheritance.
Okay.
And what will happen.
Protected properties will become the protected properties and the public properties will also become
predicted properties okay.
Now what will happen if the vacant loss if we use the excess specified private so this has private protected
and public so private properties do not participate in inheritance protected properties will become
the private properties and the public properties also will become the private properties.
Okay.
So this is the case for protected and private.
Okay.
Now what will happen if the god class is being if the home city class is inheriting that God class.
So we have only 30 class and let's say the excess specified is public.
So what will happen since this god class has the private properties and buried properties do not participate
in inheritance.
So the only asset class will be empty.
Okay.
So nothing nothing will be inherited.
Okay.
Because God class only has private properties and private properties nor participate in inheritance.
So when does a thick glass will be empty okay.
Now what lasting so ever lasting is here we using excess specify public now what will happen if I do
not mention any excess specified Okay so by default the excess modifier is private.
Okay.
So what I want to convey here is so if I will right glass God column vehicle.
If I do not mention any excess specified so by default the excess specified is private okay by default
the access specified is private.
Okay.
So I hope everything is clear.
No.
Okay.
Thank you.