1 00:00:01,810 --> 00:00:08,610 Let us know proceed and check out how do we implement the concept of overrating in case of Gorlin. 2 00:00:08,610 --> 00:00:15,390 So for those who don't know what do you mean by the concept of overriding in case of Cartland is doing 3 00:00:15,410 --> 00:00:19,250 very little check out in this day move with you with the help of example. 4 00:00:19,500 --> 00:00:27,410 Now suppose inside opening glass animal I I suppose animal eating. 5 00:00:27,810 --> 00:00:34,630 And now here inside the main method let us do one thing Legos remove all these called Elida simply call 6 00:00:35,490 --> 00:00:38,130 dog dog eat. 7 00:00:38,360 --> 00:00:48,780 And now also let us call that Gackt equally to nougat object and then simply call cat dog eat. 8 00:00:48,830 --> 00:00:51,490 And now let us rendah called LHC though. 9 00:00:52,620 --> 00:00:57,930 So here insert the output console Vigurs animal eating an animal eating both times. 10 00:00:57,960 --> 00:01:02,920 Now if you notice here I was calling dog dog eat and guide dog eat. 11 00:01:02,940 --> 00:01:11,660 Now what if I want to bring a dog he is eating and gag is eating for both dog and cat object respectively. 12 00:01:11,700 --> 00:01:17,550 So for this what do we need to do is we have to apply the concept of metor overriding in case of Cartland. 13 00:01:17,760 --> 00:01:23,400 Now there are certain truths that we need to follow in case of Cartland to apply the concept of overriding 14 00:01:23,400 --> 00:01:24,600 in case of Cartland. 15 00:01:24,810 --> 00:01:29,200 So here in case of dog Laitos override this method. 16 00:01:29,310 --> 00:01:36,540 Now all it means is redefining and mortifying this method inside their derived class or the child class. 17 00:01:36,600 --> 00:01:39,850 So here I would simply use fun. 18 00:01:40,890 --> 00:01:48,670 And then simply define a brain a statement let's say lame dog is eating. 19 00:01:48,730 --> 00:01:51,190 Now here the compiler is not happy. 20 00:01:51,220 --> 00:01:58,450 Now see we learn two plus each of the metric that we define has a public and also final word by default 21 00:01:58,510 --> 00:01:59,590 attached. 22 00:01:59,590 --> 00:02:04,330 Now this method function it also has the final keyword here. 23 00:02:04,490 --> 00:02:10,380 That simply makes it impossible for the child class to override this method here so far. 24 00:02:10,450 --> 00:02:14,210 Here we need to define the keyword of open. 25 00:02:14,410 --> 00:02:19,630 Now once this method is now open which means now this method can be ordered in. 26 00:02:19,690 --> 00:02:23,190 Inside the child class that is inside their doc class. 27 00:02:23,230 --> 00:02:25,230 Again here it shows some error. 28 00:02:25,420 --> 00:02:30,330 We need to use the override he would override SPEEs function eat. 29 00:02:30,370 --> 00:02:36,730 So this does a compiler that we are simply overriding this method from the class that is defined here 30 00:02:36,820 --> 00:02:38,400 inside the Animal class. 31 00:02:38,950 --> 00:02:42,420 And now same thing applies inside the class act as well. 32 00:02:42,680 --> 00:02:48,420 Here let us copy this called and paste this here and here. 33 00:02:48,430 --> 00:02:54,100 I will simply use GACKT is eating and now Leganes and the code. 34 00:02:54,130 --> 00:02:57,840 So here we get dog is eating GACKT is eating. 35 00:02:58,000 --> 00:03:01,450 So this is the beauty of using the concept of method overriding. 36 00:03:01,450 --> 00:03:03,880 In case of Cartland no notice here. 37 00:03:03,960 --> 00:03:08,010 This method is exactly the same as this method. 38 00:03:08,020 --> 00:03:13,190 The only difference is that here we are printing animal eating and here we are printing. 39 00:03:13,210 --> 00:03:15,130 Dog is eating like this. 40 00:03:15,130 --> 00:03:17,850 Now suppose I create an animal object. 41 00:03:17,980 --> 00:03:19,400 Say that animal. 42 00:03:19,810 --> 00:03:22,290 And then simply call animal dog eat. 43 00:03:22,390 --> 00:03:24,380 And now let's see what happens. 44 00:03:25,160 --> 00:03:27,670 So here we get annual eating in the output. 45 00:03:27,800 --> 00:03:35,000 So what is happening is that when this statement dog dog eat is executed the compiler gives more priority 46 00:03:35,390 --> 00:03:35,840 to this. 47 00:03:35,840 --> 00:03:36,940 It mattered. 48 00:03:37,100 --> 00:03:44,180 Now similarly when we call animal dog eat with the help of this animal object the compiler only looks 49 00:03:44,180 --> 00:03:46,760 for the eating method inside the Animal class. 50 00:03:46,790 --> 00:03:47,350 Right. 51 00:03:47,360 --> 00:03:52,800 So here we get animal eating and this animal don't have a superclass right. 52 00:03:52,810 --> 00:03:55,530 So Bideford this eat method will be called. 53 00:03:55,570 --> 00:03:58,290 Now same thing applies for the gag object as well. 54 00:03:58,390 --> 00:04:02,630 Gag dog eat the compiler simply looks for the eat method first. 55 00:04:02,770 --> 00:04:04,350 Inside the cat plus. 56 00:04:04,360 --> 00:04:05,780 So here we have over it. 57 00:04:05,920 --> 00:04:07,970 And it mattered here. 58 00:04:07,990 --> 00:04:11,150 GARRETT Is eating is now rendered in the output console. 59 00:04:11,410 --> 00:04:19,150 And now suppose if you want to prevent the animal eating as well as dog is eating then we call this 60 00:04:19,240 --> 00:04:20,870 statement dog dog eat. 61 00:04:20,980 --> 00:04:22,490 So in that case what to do. 62 00:04:22,540 --> 00:04:30,900 So here let's just remove all these lines of called and hear what we do is insert the dog method inside 63 00:04:30,900 --> 00:04:38,260 the old it didn't matter I would simply use a super tricky word super guard dog eat. 64 00:04:38,540 --> 00:04:45,140 So when the statement either method is executed It's simply called super dog eat method that simply 65 00:04:45,140 --> 00:04:50,220 triggers this method to present inside the animal class which is actually the superclass. 66 00:04:50,230 --> 00:04:50,850 Right. 67 00:04:50,870 --> 00:04:56,890 So this animal eating really repented and after this the control will enter this statement. 68 00:04:57,050 --> 00:05:00,850 So a dog is eating will also be printed in the output console. 69 00:05:01,310 --> 00:05:04,560 And now let us run the called. 70 00:05:04,620 --> 00:05:08,520 So here we get animal eating and also the dog is eating. 71 00:05:08,580 --> 00:05:13,930 Now notice from the main method I'm simply calling dog dog eat only once. 72 00:05:14,010 --> 00:05:14,480 Right. 73 00:05:14,640 --> 00:05:21,240 So when the statement is actually executed it simply triggers this method or here which in turn simply 74 00:05:21,240 --> 00:05:26,550 calls the method inside the Animal class and then after this. 75 00:05:26,640 --> 00:05:32,160 This method dog is eating is now printed along with the animal eating. 76 00:05:32,160 --> 00:05:34,080 So I hope that things are now clear. 77 00:05:34,270 --> 00:05:37,080 Now when we're gonna say I want to tell you. 78 00:05:37,080 --> 00:05:41,070 Now suppose this dog simply inherits from the animal claws. 79 00:05:41,190 --> 00:05:48,330 Now suppose here if I define Komarr interface name such as such as let's see it right. 80 00:05:48,390 --> 00:05:51,340 Suppose this test is actually the in Duffys. 81 00:05:51,330 --> 00:05:52,610 Now what is the interface. 82 00:05:52,620 --> 00:05:55,550 I will let you know shortly in my upcoming tutorials. 83 00:05:55,830 --> 00:06:02,900 But as of now suppose I have an animal which is a class called MarkWest which is actually the interface. 84 00:06:03,120 --> 00:06:08,910 So this will simply create a confusion for the compiler if this first message contains that it mattered 85 00:06:08,940 --> 00:06:09,780 as well. 86 00:06:09,990 --> 00:06:13,560 Like we have each mattered inside the Animal class in the same way. 87 00:06:13,560 --> 00:06:16,980 Suppose each method is also present inside that displays. 88 00:06:17,100 --> 00:06:21,030 So in that case it will simply create confusion for the compiler. 89 00:06:21,270 --> 00:06:28,380 So here just to be on the safe side I would simply use super followed by left arrow and then right arrow 90 00:06:28,540 --> 00:06:32,370 in between simply give their type as Animal class. 91 00:06:32,760 --> 00:06:36,050 And now let us read the code. 92 00:06:36,140 --> 00:06:41,050 So in the output again we get animal eating and dog eating right. 93 00:06:41,200 --> 00:06:44,770 So this was all about the method overriding in case of Cartland. 94 00:06:44,770 --> 00:06:51,970 Now what about the field variables are the properties overriding in case of Cartland can be overdyed 95 00:06:52,080 --> 00:06:54,330 discolored inside their dog. 96 00:06:54,490 --> 00:06:55,890 Yes we can. 97 00:06:55,890 --> 00:07:02,590 So for us by default the color of the animal is lacy white and now suppose from the mean there. 98 00:07:02,800 --> 00:07:10,020 If I simply print large see print line dog dord Let's see color. 99 00:07:10,490 --> 00:07:12,340 And that doesn't move this statement. 100 00:07:12,340 --> 00:07:13,470 Dog got eat. 101 00:07:13,960 --> 00:07:17,890 And now let's see the output. 102 00:07:17,960 --> 00:07:25,250 So in the outbuild we get white right which is actually their default value provided to the field variable 103 00:07:25,250 --> 00:07:27,850 of color inside the Animal class. 104 00:07:27,860 --> 00:07:33,850 Now suppose I want to override this color property inside the class dog in the same way we have done 105 00:07:33,940 --> 00:07:35,490 with the eat method. 106 00:07:35,780 --> 00:07:44,930 So for that again we need to clear that space color of the type of string equally to lurves give their 107 00:07:44,930 --> 00:07:47,780 default value as black. 108 00:07:47,920 --> 00:07:51,250 Right now here it will simply show us the error. 109 00:07:51,580 --> 00:07:58,090 And here I have to use the key word of overdyed And now here again it will show some error. 110 00:07:58,150 --> 00:08:06,070 Right now this is simply because like Leg. the class and also the method Daivari keywords all the variables 111 00:08:06,340 --> 00:08:09,660 are also public and final in nature. 112 00:08:09,970 --> 00:08:14,800 So by default you can not override this variable inside the dog method. 113 00:08:14,930 --> 00:08:16,620 It is final in nature. 114 00:08:16,750 --> 00:08:20,040 So similar to the Animal class and also the function. 115 00:08:20,260 --> 00:08:23,060 We have to make this variable as open. 116 00:08:23,530 --> 00:08:29,360 And now this variable color can not be overridden cannot be overridden inside there. 117 00:08:29,380 --> 00:08:32,390 Plus like we have been here right now. 118 00:08:32,740 --> 00:08:37,870 And now if I in the code then this statement will be executed dog dog. 119 00:08:38,110 --> 00:08:45,460 So the compiler will give more priority to this variable present inside a spoon class definition of 120 00:08:45,610 --> 00:08:46,230 dog. 121 00:08:46,510 --> 00:08:47,360 Right. 122 00:08:47,500 --> 00:08:54,930 So instead of white this time black will be printed. 123 00:08:54,960 --> 00:08:59,480 So here in the output this time we get black instead of white. 124 00:08:59,490 --> 00:09:06,870 So always remember that in order to inherit some class we need to use the key of open in order to override 125 00:09:07,110 --> 00:09:12,780 some property and also some method we need to use the keyword of open. 126 00:09:12,780 --> 00:09:19,340 And if you are overwriting something you need to use the keyword of overdyed here and here as well. 127 00:09:19,560 --> 00:09:24,600 So this was all about the method and properties overriding in case of Cartland. 128 00:09:24,600 --> 00:09:26,560 It was very simple and clear.