6.14 OOP Inheritance-3
Hello welcome in this second part on inheritance In the previous course we started to create our animal class ... Then the dog class that hears from the animal class So that means it has access to the features of ... the animal class. In this course, we will continue on the steps we have started. To start we will leave ... on the animal class which is the mother calss And we will modify our move method We will remove the ... string we will put void We will not return anything. and we’ll put a parameter setting the speed Int ... speed We’ll make an animal println. Move. and we will concatenate with the value we will receive as parameter ... So speed and we’ll go back to our dog method which is the girl class and now we can ... ask ourselves how a dog moves Run or walk so let’s create Two methods Run it take nothing in ... parameter and the second method walk in the first method we will call our move method Super move we will ... put. 10 For speed Next, we will put a println In this println we will put Dog running is ... call But also in the method We will also call our move method But different handling Speed, we will ... put 5 5, We can consider this as Kilo meter goes for hour. it is better to call our method of this ... bottle Because if we were to change, we were to make a change in our class Animal The move method ... Will be simpler to call this method. so preferably always method of this handling We will make one. println and ... then we will go back to the main class to test our code So we will put in comment this two ... line. and we’ll use our dog instance to call the move method The market method forgives. We’ll compile ... to see. and in the console you saw well that there is dog Walk call so the method dog walk ... is call and animal moves 5, the speed 5 that we put if we return to our mother class the ... line 19, we put the animal moving at the speed we put As argument here we will go back ... in our house and we call the second method. Run so the second method run function also correctly States given ... that we passed in parameter 10 we put 10 in argument. in the call of the move method I hope that ... you understood how function of the calls of the methods In the classes and now if we want to redefine our method ... move in dog we will. Perform We will generate. override method For the move method So println dog move Call ... Now, you must surely be wondering what method will be executed between this method that we have call move and the ... method that we have redefined But also the method that we have put super before so we will go in the hand ... and we will execute our program and see if The result we’ll see first, we’re going to comment...line 12 afterwards, I’ll explain the reason. we run our program you only see ... the method. that we have redefined a ete call dog move() call So As we put in the print ln ... you have to understand that if you were to put the super in front. He’s gonna call the method that’s out there. In the animal But if you were to put only move since here there are two methods, ... it will take the method that we redefine and not the method that we call here We will go back in the ... hand. We will remove the comment and we will put. Dog. walk() in comment we compile our program. As you ... saw He did not call the method. That we redefined, but rather called the method that we put. Into our Animal That Is. Animal Moves exactly the same animal moves the 10 Is due to the fact that we have ... put. 10 as an argument I hope you understood the difference between using the super and not ... putting the super What we are trying to say in Java by putting the word super, is that if y ... a. A move method in this slap dog must be used, but you have to use the move method which is ... found. In our animal class, that is to say the mother class of our dog class in other themes the class ... which hears Our dog class which is animal Now, that you understood how to call the methods. and also how to ... use the super keyword, we will Continue we will create another class our duck class Who will also ... hears of the animal class so it becomes a girl class we will call our builder. and then we’ll ... put the endurance attribute. Then we’ll generate the getters and setters. In this course, we will use them, but we ... will generate them as well. You could also put directly the arguments of our Constructor It will say that here it ... ya weigth we can put the value directly. By setting For example 23 f and this parameter We will delete it ... . And not forgetting to put endurance with this Endurance equals Now we have our builder. and the getter and ... setter We will create a nourishing method. Audience and we’re going to call the eat method that’s in our ... animal class and we’re going to redefine eat and in this method I’d like you to redefine me. That you show me the ... types of food that ducks can eat and of course to do hand tests to find out ... if your function code correctly and you can use other methods. To train you to create methods and ... make method calls between the parent class and the daughter class so the next one, we will start Other ... concepts in programming in Java So see you soon.