1 00:00:00,730 --> 00:00:05,930 Hiding the strings in the heart and welcome to the next video of the concept of inheritance in this 2 00:00:05,930 --> 00:00:10,910 video we will check out their demo for the concept of inheritance in Cartland. 3 00:00:10,910 --> 00:00:13,210 So here insert the intelligent ID. 4 00:00:13,240 --> 00:00:16,680 I've simply defined some code just to save time. 5 00:00:16,730 --> 00:00:20,370 So here I have class or dog inside the class dog. 6 00:00:20,450 --> 00:00:23,010 I have some properties of color and breed. 7 00:00:23,180 --> 00:00:25,150 Both are of their type of string. 8 00:00:25,510 --> 00:00:28,610 And I have some function of bark and eat. 9 00:00:28,610 --> 00:00:36,080 Now down the side I have another class of Gackt that contains the properties of color and age and also 10 00:00:36,080 --> 00:00:39,450 the functions of meal and eat right. 11 00:00:39,800 --> 00:00:48,890 Now if you compare both the class here we have variable color and function eat and here as well I have 12 00:00:49,190 --> 00:00:51,700 variable color and function. 13 00:00:51,950 --> 00:00:56,350 So don't you think the courts are redundant and they need to be optimized. 14 00:00:56,360 --> 00:01:00,490 The answer is yes we can optimize the code here as well. 15 00:01:00,590 --> 00:01:01,870 So how to do it. 16 00:01:01,910 --> 00:01:05,350 So here comes the concept of inheritance in the picture. 17 00:01:05,720 --> 00:01:10,640 So both cat and dog are actually animal like we all humans are. 18 00:01:10,790 --> 00:01:18,290 So here I would simply create a class of let's say animal and now inside this I would simply define 19 00:01:18,650 --> 00:01:22,120 this variable colored simply. 20 00:01:23,550 --> 00:01:29,720 And pasted inside the class of animal and then simply go the function of it from here. 21 00:01:30,480 --> 00:01:38,160 And then we stayed inside the class of animal and now simply removed the white space he had as well. 22 00:01:38,310 --> 00:01:44,980 And now inside the guard let us remove the VAT colored and also remove this function. 23 00:01:45,010 --> 00:01:47,260 Eat. 24 00:01:47,370 --> 00:01:51,360 So here we will apply the concept of inheritance in case of dog. 25 00:01:51,590 --> 00:01:53,890 So fair play inheritance in Gears of Cartland. 26 00:01:54,080 --> 00:01:59,380 We will use galloon space animal right now here. 27 00:01:59,400 --> 00:02:00,710 It will show some error. 28 00:02:00,740 --> 00:02:02,200 Let me tell you about Izard. 29 00:02:02,210 --> 00:02:10,280 Similarly in case of cat as well I will simply use Golon space animal now in the previous video we talked 30 00:02:10,280 --> 00:02:13,420 about the property of a class such as Bideford. 31 00:02:13,420 --> 00:02:16,020 The classes are public and final. 32 00:02:16,100 --> 00:02:21,860 So by default you can not inherit the properties of a class and to apply the concept of inheritance. 33 00:02:21,950 --> 00:02:25,010 You have to use the keyboard of open. 34 00:02:25,090 --> 00:02:30,700 So here Bideford Vortiger class and functions are variables that you would define in case of Cartland 35 00:02:31,180 --> 00:02:35,050 are actually public and final in nature. 36 00:02:35,110 --> 00:02:35,800 Right. 37 00:02:35,860 --> 00:02:42,790 So here it shows that these two are actually redundant because Bideford every class is public and every 38 00:02:42,790 --> 00:02:44,300 class is final. 39 00:02:44,320 --> 00:02:51,280 Now the same applies to this very well as well which is again public in nature by Bideford and also 40 00:02:51,280 --> 00:02:53,350 final in nature by default. 41 00:02:53,410 --> 00:02:59,740 So you need not to specify it explicitly because this is their default behavior in Gotland. 42 00:02:59,800 --> 00:03:02,470 So let us remove it here now. 43 00:03:02,560 --> 00:03:08,930 Same thing applies to this class animal as well where this class is actually public and final. 44 00:03:09,010 --> 00:03:16,000 So that is why the compiler will simply throw an error that this animal is actually public and final 45 00:03:16,000 --> 00:03:17,650 and cannot be inherited. 46 00:03:17,890 --> 00:03:23,500 So by default when you want to inherit some properties in case of Cartland you have to make a class 47 00:03:23,590 --> 00:03:26,460 open by using the open keyword. 48 00:03:26,470 --> 00:03:32,370 Now as soon as you declare open so this class is now no longer final in nature. 49 00:03:33,220 --> 00:03:36,100 And this class can be inherited in case of dog. 50 00:03:36,100 --> 00:03:40,900 And also in case of cat and now Lexi what is it again. 51 00:03:40,930 --> 00:03:45,140 So here it says that the animal has to be a type of constructor. 52 00:03:45,340 --> 00:03:48,450 So here I would simply use a constructor sign. 53 00:03:48,640 --> 00:03:50,500 And now the error has gone. 54 00:03:50,500 --> 00:03:54,740 And similarly in case of ladies use a constructor sign. 55 00:03:55,030 --> 00:03:57,220 And now again the error has gone. 56 00:03:57,220 --> 00:04:05,180 So let us move inside the main method and here I will simply declare that dog equal to Lerche C dog. 57 00:04:05,410 --> 00:04:08,050 So this was simply clear the object of their dog. 58 00:04:08,350 --> 00:04:18,000 Now I can simply use dog dog breed equal to let's see Lambro and similarly dog. 59 00:04:18,120 --> 00:04:26,870 Let's see color equal to let's say black and now Similarly I can simply call the method such as dog 60 00:04:26,920 --> 00:04:36,280 Darbar and also dog dog eat but I now notice here that this dog dark color is actually the part of class 61 00:04:36,370 --> 00:04:40,620 animal that we have inherited inside the class of dog. 62 00:04:40,690 --> 00:04:46,810 And similarly then we call these dog dog eat method then it is simply calling the method present inside 63 00:04:46,810 --> 00:04:47,700 the animal. 64 00:04:47,720 --> 00:04:51,580 Plus now the same thing will apply for the cat object. 65 00:04:51,610 --> 00:04:53,960 So let us define the cat object. 66 00:04:54,100 --> 00:05:00,970 So here as well we are calling God dark colored dark simply points to this color very well present inside 67 00:05:00,970 --> 00:05:02,290 the Animal class. 68 00:05:02,500 --> 00:05:04,060 And similarly Gagg dog. 69 00:05:04,090 --> 00:05:10,130 It simply triggers this method in the Animal class and now at the end Cephalus. 70 00:05:10,150 --> 00:05:17,130 If I create that espies animal equal to animal Let's see what happens. 71 00:05:17,860 --> 00:05:21,150 And then if I use animal dot operator. 72 00:05:21,250 --> 00:05:28,270 So here you will find only two options color equal to let's see white by different animals. 73 00:05:28,290 --> 00:05:28,730 Right. 74 00:05:28,780 --> 00:05:29,450 Let's see. 75 00:05:29,530 --> 00:05:35,600 Let's call it white animal or dog let's see eat and now apart from colored and eat. 76 00:05:35,680 --> 00:05:41,890 You don't have any properties inside the animal class because this animal is actually their top level 77 00:05:41,890 --> 00:05:45,290 class that does not inherit from any other class. 78 00:05:45,310 --> 00:05:46,320 Right. 79 00:05:46,360 --> 00:05:51,940 So in this video we learn the basics of how do we apply inheritance in case of Cartland. 80 00:05:52,330 --> 00:05:57,800 And now if you run the code then these methods will be called and you will get some output in the output 81 00:05:57,860 --> 00:06:02,430 console such as eat bark and meal something like that. 82 00:06:02,440 --> 00:06:07,870 So in this video we learn the basics of how do we apply the inheritance in case of Cartland. 83 00:06:08,050 --> 00:06:13,410 And now there are a lot more things that need to be discussed from the next video onwards. 84 00:06:13,570 --> 00:06:15,640 So let's check it out in the next review.