Hiding the strings in the heart and welcome to the next video of the concept of inheritance in this
video we will check out their demo for the concept of inheritance in Cartland.
So here insert the intelligent ID.
I've simply defined some code just to save time.
So here I have class or dog inside the class dog.
I have some properties of color and breed.
Both are of their type of string.
And I have some function of bark and eat.
Now down the side I have another class of Gackt that contains the properties of color and age and also
the functions of meal and eat right.
Now if you compare both the class here we have variable color and function eat and here as well I have
variable color and function.
So don't you think the courts are redundant and they need to be optimized.
The answer is yes we can optimize the code here as well.
So how to do it.
So here comes the concept of inheritance in the picture.
So both cat and dog are actually animal like we all humans are.
So here I would simply create a class of let's say animal and now inside this I would simply define
this variable colored simply.
And pasted inside the class of animal and then simply go the function of it from here.
And then we stayed inside the class of animal and now simply removed the white space he had as well.
And now inside the guard let us remove the VAT colored and also remove this function.
Eat.
So here we will apply the concept of inheritance in case of dog.
So fair play inheritance in Gears of Cartland.
We will use galloon space animal right now here.
It will show some error.
Let me tell you about Izard.
Similarly in case of cat as well I will simply use Golon space animal now in the previous video we talked
about the property of a class such as Bideford.
The classes are public and final.
So by default you can not inherit the properties of a class and to apply the concept of inheritance.
You have to use the keyboard of open.
So here Bideford Vortiger class and functions are variables that you would define in case of Cartland
are actually public and final in nature.
Right.
So here it shows that these two are actually redundant because Bideford every class is public and every
class is final.
Now the same applies to this very well as well which is again public in nature by Bideford and also
final in nature by default.
So you need not to specify it explicitly because this is their default behavior in Gotland.
So let us remove it here now.
Same thing applies to this class animal as well where this class is actually public and final.
So that is why the compiler will simply throw an error that this animal is actually public and final
and cannot be inherited.
So by default when you want to inherit some properties in case of Cartland you have to make a class
open by using the open keyword.
Now as soon as you declare open so this class is now no longer final in nature.
And this class can be inherited in case of dog.
And also in case of cat and now Lexi what is it again.
So here it says that the animal has to be a type of constructor.
So here I would simply use a constructor sign.
And now the error has gone.
And similarly in case of ladies use a constructor sign.
And now again the error has gone.
So let us move inside the main method and here I will simply declare that dog equal to Lerche C dog.
So this was simply clear the object of their dog.
Now I can simply use dog dog breed equal to let's see Lambro and similarly dog.
Let's see color equal to let's say black and now Similarly I can simply call the method such as dog
Darbar and also dog dog eat but I now notice here that this dog dark color is actually the part of class
animal that we have inherited inside the class of dog.
And similarly then we call these dog dog eat method then it is simply calling the method present inside
the animal.
Plus now the same thing will apply for the cat object.
So let us define the cat object.
So here as well we are calling God dark colored dark simply points to this color very well present inside
the Animal class.
And similarly Gagg dog.
It simply triggers this method in the Animal class and now at the end Cephalus.
If I create that espies animal equal to animal Let's see what happens.
And then if I use animal dot operator.
So here you will find only two options color equal to let's see white by different animals.
Right.
Let's see.
Let's call it white animal or dog let's see eat and now apart from colored and eat.
You don't have any properties inside the animal class because this animal is actually their top level
class that does not inherit from any other class.
Right.
So in this video we learn the basics of how do we apply inheritance in case of Cartland.
And now if you run the code then these methods will be called and you will get some output in the output
console such as eat bark and meal something like that.
So in this video we learn the basics of how do we apply the inheritance in case of Cartland.
And now there are a lot more things that need to be discussed from the next video onwards.
So let's check it out in the next review.