Inheritance Java course video

6.13 OOP Inheritance-2

Hello welcome, in this new course in which we will practice the inheritance Starting from the example we saw ... in the previous course, that is to say the animal class and The girls, dogs and duck class. So, to start, we’re going to...create an animal class. And we’re going to put the properties that go with it. There were two properties. The name... And the size that is name And weigth therefore private Then We will generate the constructor. generate Builder And then ... we have two methods eat public We’re going to put eat We’re going to come back to this method. Can there be the ... move public move method we’ll go back to move and then we’ll come back to this method. Finally... we will generate the getters and setters. And then we have our Animal class we will create the dog class. and the so that our dog class then inherit the animal class we will put the keywords extend which ... means that one class inherits another class so the we will put animal and our animal class will ... are my mother class and dog is going to be the girl class and you saw that we have a mistake and this ... error due to the fact that we did not import the manufacturer of the Animal class it wants of the Mother class ... so to import this manufacturer we will use the super keyword so we will generate. the constructor generate Constructor and ... as you saw us von t Import the name name and weigth and the keyword super il et utiliser ... pour appeler des méthodes de superclasse cest-the parent class and to access the constructor of the parent class ... so the we will access. To the attribute of the parent class name and the weigth so it means that ... in our dog class, we can use. the attributes of our Mother class that is animal Now we can put ... the attributes that are missing. For the dog class so there was the color attribute we will put color in English ... so color We can another builder for our dog class But we already have a builder. here Who calls ... the builder of our mother class so let’s just add. color In this constructor and we will reference ccolor ... equals color and we will generate getters and setters. Now, we’ll do a test to see if the inheritance ... function correctly so we’ll create a main class we’ll create an animal instance so Animal We’ll put ... arguments. The name, we’ll put Bullgod the size, we’ll put chance we’ll put. Then we’ll ... create an instance. Dog As you saw in dog it the parameter name Size and color while our ... attribute In dog these only color so let’s call the Animal builder has access to all the attributes and ... the builder we have Use In the manufacturer, we have the name. name weigth and color So we will go back ... in the hand, we will put the name we will call it. name we will put scott then size and ... color black and there we will call our method eat that we created in animal the method eat So we ... go in the hand We will put dog if you saw it dog has access to the methods that we have ... create in our class mother class. dog has access to the method eat steps given that. In our class ... cien chien extend animal means that it has access to the owner and methods of the animal class So ... we will compile our program. So the console, we don’t have any back stams that our method a string so ... we will shout an equal string eat variable we will recompile our program. So the console, we’ll see eat ... eat Who in animal Now we’ll go back to our dog class I’ll also show you the keyword ... override. We’re gonna generate this. Generate override method override method is used to define a method that inherits the ... parent class So, here, we will define the eat method We generate We can modify it. We’ll put. dog... and then we’ll go back to our class hand. and we’ll compile our program. Given that on the ... line 8, we called the eat method and defined the eat method in our dog class by ... compiling our program we are going to call the method that we defined that eat we defined in Our dog class ... So on the way out we’re going to have dog eat So here’s dog eat Thanks for taking this course in the next, ... we’ll continue and create our second class Duck so see you soon.