Let us know proceed and check out how do we implement the concept of overrating in case of Gorlin.
So for those who don't know what do you mean by the concept of overriding in case of Cartland is doing
very little check out in this day move with you with the help of example.
Now suppose inside opening glass animal I I suppose animal eating.
And now here inside the main method let us do one thing Legos remove all these called Elida simply call
dog dog eat.
And now also let us call that Gackt equally to nougat object and then simply call cat dog eat.
And now let us rendah called LHC though.
So here insert the output console Vigurs animal eating an animal eating both times.
Now if you notice here I was calling dog dog eat and guide dog eat.
Now what if I want to bring a dog he is eating and gag is eating for both dog and cat object respectively.
So for this what do we need to do is we have to apply the concept of metor overriding in case of Cartland.
Now there are certain truths that we need to follow in case of Cartland to apply the concept of overriding
in case of Cartland.
So here in case of dog Laitos override this method.
Now all it means is redefining and mortifying this method inside their derived class or the child class.
So here I would simply use fun.
And then simply define a brain a statement let's say lame dog is eating.
Now here the compiler is not happy.
Now see we learn two plus each of the metric that we define has a public and also final word by default
attached.
Now this method function it also has the final keyword here.
That simply makes it impossible for the child class to override this method here so far.
Here we need to define the keyword of open.
Now once this method is now open which means now this method can be ordered in.
Inside the child class that is inside their doc class.
Again here it shows some error.
We need to use the override he would override SPEEs function eat.
So this does a compiler that we are simply overriding this method from the class that is defined here
inside the Animal class.
And now same thing applies inside the class act as well.
Here let us copy this called and paste this here and here.
I will simply use GACKT is eating and now Leganes and the code.
So here we get dog is eating GACKT is eating.
So this is the beauty of using the concept of method overriding.
In case of Cartland no notice here.
This method is exactly the same as this method.
The only difference is that here we are printing animal eating and here we are printing.
Dog is eating like this.
Now suppose I create an animal object.
Say that animal.
And then simply call animal dog eat.
And now let's see what happens.
So here we get annual eating in the output.
So what is happening is that when this statement dog dog eat is executed the compiler gives more priority
to this.
It mattered.
Now similarly when we call animal dog eat with the help of this animal object the compiler only looks
for the eating method inside the Animal class.
Right.
So here we get animal eating and this animal don't have a superclass right.
So Bideford this eat method will be called.
Now same thing applies for the gag object as well.
Gag dog eat the compiler simply looks for the eat method first.
Inside the cat plus.
So here we have over it.
And it mattered here.
GARRETT Is eating is now rendered in the output console.
And now suppose if you want to prevent the animal eating as well as dog is eating then we call this
statement dog dog eat.
So in that case what to do.
So here let's just remove all these lines of called and hear what we do is insert the dog method inside
the old it didn't matter I would simply use a super tricky word super guard dog eat.
So when the statement either method is executed It's simply called super dog eat method that simply
triggers this method to present inside the animal class which is actually the superclass.
Right.
So this animal eating really repented and after this the control will enter this statement.
So a dog is eating will also be printed in the output console.
And now let us run the called.
So here we get animal eating and also the dog is eating.
Now notice from the main method I'm simply calling dog dog eat only once.
Right.
So when the statement is actually executed it simply triggers this method or here which in turn simply
calls the method inside the Animal class and then after this.
This method dog is eating is now printed along with the animal eating.
So I hope that things are now clear.
Now when we're gonna say I want to tell you.
Now suppose this dog simply inherits from the animal claws.
Now suppose here if I define Komarr interface name such as such as let's see it right.
Suppose this test is actually the in Duffys.
Now what is the interface.
I will let you know shortly in my upcoming tutorials.
But as of now suppose I have an animal which is a class called MarkWest which is actually the interface.
So this will simply create a confusion for the compiler if this first message contains that it mattered
as well.
Like we have each mattered inside the Animal class in the same way.
Suppose each method is also present inside that displays.
So in that case it will simply create confusion for the compiler.
So here just to be on the safe side I would simply use super followed by left arrow and then right arrow
in between simply give their type as Animal class.
And now let us read the code.
So in the output again we get animal eating and dog eating right.
So this was all about the method overriding in case of Cartland.
Now what about the field variables are the properties overriding in case of Cartland can be overdyed
discolored inside their dog.
Yes we can.
So for us by default the color of the animal is lacy white and now suppose from the mean there.
If I simply print large see print line dog dord Let's see color.
And that doesn't move this statement.
Dog got eat.
And now let's see the output.
So in the outbuild we get white right which is actually their default value provided to the field variable
of color inside the Animal class.
Now suppose I want to override this color property inside the class dog in the same way we have done
with the eat method.
So for that again we need to clear that space color of the type of string equally to lurves give their
default value as black.
Right now here it will simply show us the error.
And here I have to use the key word of overdyed And now here again it will show some error.
Right now this is simply because like Leg. the class and also the method Daivari keywords all the variables
are also public and final in nature.
So by default you can not override this variable inside the dog method.
It is final in nature.
So similar to the Animal class and also the function.
We have to make this variable as open.
And now this variable color can not be overridden cannot be overridden inside there.
Plus like we have been here right now.
And now if I in the code then this statement will be executed dog dog.
So the compiler will give more priority to this variable present inside a spoon class definition of
dog.
Right.
So instead of white this time black will be printed.
So here in the output this time we get black instead of white.
So always remember that in order to inherit some class we need to use the key of open in order to override
some property and also some method we need to use the keyword of open.
And if you are overwriting something you need to use the keyword of overdyed here and here as well.
So this was all about the method and properties overriding in case of Cartland.
It was very simple and clear.