1 00:00:00,150 --> 00:00:05,490 ‫In this video, you are going to learn about inheritance in C sharp or in programming in general. 2 00:00:05,520 --> 00:00:11,220 ‫I'm going to try to keep it super simple because it can become quite complicated if you look at it because 3 00:00:11,220 --> 00:00:12,180 ‫there is a lot going on. 4 00:00:12,180 --> 00:00:19,560 ‫But I'm going to simplify it as much as possible because the idea of inheritance is really the reusability 5 00:00:19,560 --> 00:00:20,340 ‫of code. 6 00:00:20,340 --> 00:00:26,520 ‫And this allows us not only to reduce our own code, but reduce code of other developers or even of 7 00:00:26,520 --> 00:00:32,970 ‫other namespaces directly without having to write a lot of code manually again and again and again, 8 00:00:32,970 --> 00:00:34,430 ‫which was there before. 9 00:00:34,440 --> 00:00:38,640 ‫And this really reduces repeated or redundant code. 10 00:00:39,120 --> 00:00:46,860 ‫So the idea of inheritance is basically it's a fundamental concept of object oriented programming. 11 00:00:46,890 --> 00:00:54,540 ‫It allows you to define a child class that reuses or inherits, extends, or modifies a parent class's 12 00:00:54,540 --> 00:00:55,320 ‫behavior. 13 00:00:55,860 --> 00:00:59,870 ‫The class whose members are inherited is called the base class. 14 00:00:59,880 --> 00:01:04,770 ‫The class that inherits the members of the base class is called the derived class. 15 00:01:05,380 --> 00:01:06,990 ‫Okay, so what does this mean? 16 00:01:07,050 --> 00:01:11,790 ‫Well, in simple terms, if you have more than one class with the same code or functionality, but it 17 00:01:11,790 --> 00:01:16,980 ‫differs slightly, we can actually put this repeated or redundant code in a separate class and then 18 00:01:16,980 --> 00:01:20,160 ‫make our class this inherit from it. 19 00:01:20,280 --> 00:01:26,940 ‫This code can be method's functionality, so to speak, or properties which are the attributes of our 20 00:01:26,940 --> 00:01:27,690 ‫classes. 21 00:01:27,840 --> 00:01:29,700 ‫So let's look at an example. 22 00:01:29,700 --> 00:01:33,810 ‫And therefore I created a new project here, which I call Inheritance Demo. 23 00:01:34,380 --> 00:01:36,840 ‫All right, so let's go ahead and look at this example. 24 00:01:36,840 --> 00:01:41,940 ‫So usually when you are working with multiple classes, you go ahead and create a new class here. 25 00:01:42,150 --> 00:01:43,890 ‫So let's do that here as well. 26 00:01:43,920 --> 00:01:48,840 ‫You could, of course, create the class in the same file, but that's not good practice. 27 00:01:48,840 --> 00:01:51,930 ‫So let's go ahead and call this class radio. 28 00:01:51,960 --> 00:01:52,290 ‫All right. 29 00:01:52,290 --> 00:01:55,530 ‫So here's the class, say radio ad. 30 00:01:55,530 --> 00:01:59,460 ‫And now we have this radial class, which is in the same namespace. 31 00:01:59,730 --> 00:02:05,070 ‫So both classes, the program C is where we have our main method, which is the starting point of our 32 00:02:05,070 --> 00:02:08,520 ‫application and the radial class are in the same file. 33 00:02:08,550 --> 00:02:10,560 ‫So we're going to have two classes. 34 00:02:10,560 --> 00:02:13,560 ‫One will be radio and the other one will be TV. 35 00:02:13,650 --> 00:02:15,690 ‫Let's just assume we have a couple of properties. 36 00:02:15,690 --> 00:02:21,810 ‫So for example, a boolean that determines the state of the radio is it turned on, and then the brand 37 00:02:21,810 --> 00:02:22,590 ‫of the radio. 38 00:02:22,590 --> 00:02:26,400 ‫So is it Panasonic or whatever other brands there are? 39 00:02:26,670 --> 00:02:33,900 ‫And then we have a simple constructor here, so you should definitely have an understanding of the core 40 00:02:33,900 --> 00:02:35,130 ‫concepts of classes. 41 00:02:35,130 --> 00:02:40,050 ‫If you want to fully understand inheritance, that's generally something that I would recommend understanding 42 00:02:40,050 --> 00:02:43,380 ‫before getting to inheritance because it's building on top of each other. 43 00:02:43,850 --> 00:02:44,130 ‫Okay. 44 00:02:44,160 --> 00:02:49,620 ‫So then I want to have two methods because this is basically going to be the functionality. 45 00:02:49,620 --> 00:02:56,160 ‫So one is going to switch the radio on, it will be the switch on method and the other one will be the 46 00:02:56,160 --> 00:02:57,090 ‫switch off method. 47 00:02:57,090 --> 00:03:02,400 ‫So you can turn the radio on and off or switch it on off using these two methods. 48 00:03:02,550 --> 00:03:08,610 ‫And then we will have another method which will allow us to listen to the radio. 49 00:03:09,090 --> 00:03:14,070 ‫So we have this method here called Listen Radio and it will check. 50 00:03:14,100 --> 00:03:16,200 ‫Is the radio turned on right now? 51 00:03:16,200 --> 00:03:21,540 ‫So is this is on property here, this boolean, is it going to be in fact true? 52 00:03:21,540 --> 00:03:27,180 ‫And if that's true, then we can listen to the radio and the way we are going to indicate that we are 53 00:03:27,180 --> 00:03:32,660 ‫listening to the radio will just be with this console red line statement saying listening to the radio 54 00:03:32,670 --> 00:03:39,000 ‫and otherwise we're going to print this error message saying radio is switched off, switch it on first. 55 00:03:39,030 --> 00:03:39,240 ‫Okay. 56 00:03:39,240 --> 00:03:43,230 ‫So before we can listen to it, we need to turn it on. 57 00:03:43,320 --> 00:03:43,710 ‫All right. 58 00:03:43,710 --> 00:03:45,480 ‫So that's our radio now. 59 00:03:45,510 --> 00:03:49,530 ‫Now, imagine you have another class, which is going to be. 60 00:03:50,450 --> 00:03:51,740 ‫The TV. 61 00:03:52,070 --> 00:03:54,050 ‫So let's go ahead and create a new class. 62 00:03:54,050 --> 00:04:00,380 ‫And therefore you can go over here to add and then add class and give this class a name. 63 00:04:00,380 --> 00:04:02,000 ‫I'm going to call it TV. 64 00:04:02,120 --> 00:04:09,440 ‫And now in this class, I will go ahead and have a couple of properties similarly to what we had here. 65 00:04:09,440 --> 00:04:15,410 ‫So basically, I'm going to also have the state if it's turned on or off. 66 00:04:15,440 --> 00:04:17,840 ‫So let's add those two properties in here. 67 00:04:17,870 --> 00:04:23,660 ‫Then I will have a simple constructor which allows me to set those values when I'm creating a new object 68 00:04:23,660 --> 00:04:24,650 ‫of TV. 69 00:04:24,650 --> 00:04:29,960 ‫So here pull is on as well as string brand, which sets the properties. 70 00:04:30,770 --> 00:04:40,220 ‫Then I will have the individual other methods so I can turn on the TV and turn it off similar to what 71 00:04:40,220 --> 00:04:43,790 ‫I did in the radio so I can basically copy this code. 72 00:04:43,790 --> 00:04:48,920 ‫But it will be slightly different because we had the comments which said radio here, but now this will 73 00:04:48,920 --> 00:04:49,610 ‫be TV. 74 00:04:49,610 --> 00:04:55,190 ‫So this method will turn on the TV and this one will turn it off or switch it off. 75 00:04:56,030 --> 00:05:05,180 ‫So then we just need to have another method which will allow us to watch the TV and it will do something 76 00:05:05,180 --> 00:05:07,520 ‫very similar to what our radio does. 77 00:05:07,550 --> 00:05:12,560 ‫It allows us to watch the TV only if the TV is on. 78 00:05:12,590 --> 00:05:15,800 ‫If it's off, we will need to turn on the TV first. 79 00:05:16,280 --> 00:05:21,170 ‫Okay, so now we have these two classes and if you look at them, they are awfully similar. 80 00:05:21,200 --> 00:05:27,920 ‫So there is a lot of stuff that is exactly the same, basically because this property is on as well 81 00:05:27,920 --> 00:05:29,720 ‫as this brand, they are the same. 82 00:05:29,720 --> 00:05:33,080 ‫We have them in both classes, so basically we have redundant code. 83 00:05:33,080 --> 00:05:37,850 ‫We had to copy and paste a bunch of code and it's more or less the same. 84 00:05:38,210 --> 00:05:46,820 ‫So how can we make it so that we don't have to copy and paste a lot of code and rewrite code and basically 85 00:05:46,820 --> 00:05:47,810 ‫have redundant code? 86 00:05:47,810 --> 00:05:52,130 ‫Well, that's the whole point of the concept of inheritance. 87 00:05:52,130 --> 00:05:54,710 ‫So inheritance comes to the rescue. 88 00:05:54,740 --> 00:05:59,810 ‫We can solve this issue by creating a third class called electrical device. 89 00:05:59,810 --> 00:06:05,210 ‫This will contain all of the shared functionalities and properties of an electrical device we have. 90 00:06:05,210 --> 00:06:07,550 ‫So let's look at those. 91 00:06:07,550 --> 00:06:10,520 ‫What are the ones that we have that are the same? 92 00:06:10,520 --> 00:06:15,200 ‫So what are the properties that are the same for our TV as well as the radio? 93 00:06:15,410 --> 00:06:21,020 ‫Well, it's in our case all of the properties, actually, but it doesn't have to be all of them. 94 00:06:21,020 --> 00:06:23,690 ‫In this case it will be because we don't have more properties. 95 00:06:23,690 --> 00:06:26,840 ‫But the two properties that we have that will be the same. 96 00:06:26,840 --> 00:06:33,860 ‫So is on and brand are both properties that exist in TV as well as in radio. 97 00:06:34,040 --> 00:06:40,280 ‫So our new class should have those two properties and then we have the two methods which allow us to 98 00:06:40,310 --> 00:06:46,760 ‫switch the TV on, the radio on or the radio off and the TV off as well. 99 00:06:47,840 --> 00:06:54,920 ‫So for you, a little exercise if you want to try this, because I assume that you are not a pro and 100 00:06:54,920 --> 00:06:58,790 ‫programming at that point, but you will feel a lot more confident when you try this. 101 00:06:58,790 --> 00:07:06,980 ‫So go ahead and create a class that has all of these properties and these methods that we can or that 102 00:07:06,980 --> 00:07:12,080 ‫are shared between the two classes, create them in a separate class and call this class electrical 103 00:07:12,080 --> 00:07:12,950 ‫device. 104 00:07:12,950 --> 00:07:17,360 ‫Actually, you can call it however you want, but I'm going to call it electrical device like such. 105 00:07:18,510 --> 00:07:18,960 ‫Okay. 106 00:07:18,990 --> 00:07:21,000 ‫So I hope you passed the video and tried it. 107 00:07:21,000 --> 00:07:25,620 ‫So I'm going to create a new class and put a way, of course, you see, you can use the shortcut control 108 00:07:25,620 --> 00:07:27,390 ‫case, so let's do that. 109 00:07:27,390 --> 00:07:35,850 ‫In this case, Control K C and this will open up this window here and let me change it to electrical. 110 00:07:36,990 --> 00:07:39,000 ‫Device like so. 111 00:07:39,330 --> 00:07:44,280 ‫And now this class will have the properties that we are sharing between the two other classes. 112 00:07:44,280 --> 00:07:45,720 ‫So let me put them in here. 113 00:07:45,750 --> 00:07:49,650 ‫The boolean that determines the state of the electrical device, is it turned on or not? 114 00:07:49,920 --> 00:07:51,720 ‫And then the brand of the device. 115 00:07:52,020 --> 00:07:56,310 ‫And then of course, we need to have a constructor. 116 00:07:56,430 --> 00:07:58,680 ‫So electrical device is on. 117 00:07:58,680 --> 00:08:02,910 ‫And Brent and finally we have the functionality which are methods. 118 00:08:02,910 --> 00:08:08,190 ‫So whenever you have functionality, you put them into methods and the functionality is to turn something 119 00:08:08,190 --> 00:08:09,750 ‫on or turn something off. 120 00:08:09,750 --> 00:08:14,970 ‫So whenever there is an action happening with your class or with the object that you are using, you 121 00:08:14,970 --> 00:08:16,680 ‫will need to use methods. 122 00:08:16,890 --> 00:08:18,090 ‫And that's what we're doing here. 123 00:08:18,090 --> 00:08:24,870 ‫So we're using a method to turn something on, in this case the electrical device, and to turn it off 124 00:08:24,870 --> 00:08:26,790 ‫or switch it on and switch it off. 125 00:08:26,790 --> 00:08:26,970 ‫Okay. 126 00:08:27,060 --> 00:08:29,790 ‫So that's basically what we're doing here. 127 00:08:29,790 --> 00:08:35,160 ‫So now that we have our shared properties and methods in one class, let's make the other class of the 128 00:08:35,160 --> 00:08:42,330 ‫TV and radio classes inherit from this class or in other words, extend this class. 129 00:08:42,570 --> 00:08:45,270 ‫So this is just a different term that you can use here. 130 00:08:45,390 --> 00:08:51,120 ‫So our TV and our radio will now extend the electrical devices class. 131 00:08:51,330 --> 00:08:52,950 ‫So how can we do that? 132 00:08:52,950 --> 00:08:55,890 ‫Well, let's start with the radio, because the TV will be done. 133 00:08:55,890 --> 00:08:57,090 ‫A little challenge for you. 134 00:08:57,090 --> 00:08:57,270 ‫What? 135 00:08:57,270 --> 00:08:59,400 ‫You will have to do it yourself. 136 00:08:59,400 --> 00:09:08,100 ‫So here you use the colon and then the name of the class that you want to inherit from electrical device 137 00:09:08,100 --> 00:09:16,050 ‫is the class that our radio now will inherit from, or our radio will extend the functionality of the 138 00:09:16,050 --> 00:09:17,910 ‫electrical device class. 139 00:09:18,850 --> 00:09:19,330 ‫Okay. 140 00:09:19,330 --> 00:09:22,660 ‫So Colon and then the name of the class that you want to extend. 141 00:09:22,660 --> 00:09:29,620 ‫And what's important is, is of course, that this class has to be either in the same namespace or you 142 00:09:29,620 --> 00:09:32,200 ‫have to add the namespace up here. 143 00:09:32,200 --> 00:09:37,240 ‫So in our case, we're not using any of those, we're just using system, but as we are in the same 144 00:09:37,240 --> 00:09:42,610 ‫namespace, so the electrical device says class is in the same namespace as radio and TV. 145 00:09:42,610 --> 00:09:47,920 ‫We can just do it like so, but now we can see that our boolean has a warning here. 146 00:09:47,920 --> 00:09:55,510 ‫So when you hover over your ID, so Visual Studio is going to tell you Radio DOT is on hides, inherited 147 00:09:55,510 --> 00:10:00,400 ‫member electrical devices is on use the new keyword if hiding was intended. 148 00:10:00,760 --> 00:10:10,090 ‫So basically we are using the same property name and here you want to avoid that because you have this 149 00:10:10,090 --> 00:10:14,770 ‫property, so to speak, already because you're inheriting it from the electrical device. 150 00:10:14,980 --> 00:10:22,030 ‫So now you can just hide it or override it with this one that you have created here if you want to use 151 00:10:22,030 --> 00:10:27,190 ‫something with the exact same name, but it should behave somehow differently, then you can do that. 152 00:10:27,190 --> 00:10:31,150 ‫Even though that's not good practice necessarily depends on the use case, of course. 153 00:10:31,150 --> 00:10:39,340 ‫So this is because now the radio class contains two properties of the same name we are hiding or covering. 154 00:10:39,340 --> 00:10:40,600 ‫That's a different term here. 155 00:10:40,600 --> 00:10:44,860 ‫The properties that we inherited from the electrical device class. 156 00:10:44,860 --> 00:10:48,730 ‫So we will remove the redundant code that we don't need anymore. 157 00:10:48,730 --> 00:10:49,960 ‫So let's get rid of that. 158 00:10:50,200 --> 00:10:54,970 ‫And of course the redundant code is not just assigning or creating the properties but also having these 159 00:10:54,970 --> 00:10:55,690 ‫methods here. 160 00:10:55,690 --> 00:10:57,520 ‫So let's get rid of those as well. 161 00:10:57,910 --> 00:11:04,810 ‫Now we have another error that appears here and that is this radio constructor that seems to have an 162 00:11:04,810 --> 00:11:05,410 ‫issue. 163 00:11:05,440 --> 00:11:12,220 ‫It says there is no argument given that corresponds to the required formal parameter is on of electrical 164 00:11:12,220 --> 00:11:14,770 ‫device, electrical device, pool string. 165 00:11:14,980 --> 00:11:17,590 ‫So what is this electrical device or electrical device? 166 00:11:17,590 --> 00:11:20,770 ‫Pool string Well, it's this one here. 167 00:11:20,770 --> 00:11:22,240 ‫It's this constructor. 168 00:11:22,240 --> 00:11:28,870 ‫Since our properties are coming from the base class and our base class contains a constructor, we can 169 00:11:28,870 --> 00:11:32,380 ‫use the base keyword to pass our base class. 170 00:11:32,410 --> 00:11:39,100 ‫It's constructor arguments because these are the only two properties we have and our constructor in 171 00:11:39,100 --> 00:11:41,530 ‫the child class will have an empty body. 172 00:11:41,860 --> 00:11:44,290 ‫So that is a lot of talk. 173 00:11:44,290 --> 00:11:49,450 ‫But basically what this means is because our radio constructor isn't any more complex than the base 174 00:11:49,450 --> 00:11:57,160 ‫one, we can just go ahead and say base and here is on and brand. 175 00:11:58,300 --> 00:11:59,080 ‫Like so. 176 00:11:59,110 --> 00:12:02,260 ‫And then we don't need a body for our radio. 177 00:12:02,530 --> 00:12:08,410 ‫So this constructor will basically say please pass the is on as well as the brand properties that are 178 00:12:08,410 --> 00:12:16,300 ‫passed to the radio object that when it's created pass it over to the electrical device constructor 179 00:12:16,300 --> 00:12:23,560 ‫because basically our radio is inheriting from electrical device and therefore we can do that so we 180 00:12:23,560 --> 00:12:26,080 ‫can just pass it over to electrical device. 181 00:12:26,080 --> 00:12:32,440 ‫And what that will do is it will basically set the properties is on as well as brand based on the values 182 00:12:32,440 --> 00:12:33,340 ‫that are passed. 183 00:12:34,090 --> 00:12:34,870 ‫So this is. 184 00:12:35,610 --> 00:12:37,170 ‫The more complicated part. 185 00:12:37,170 --> 00:12:43,560 ‫But the power here is really that we don't have to build redundant code and well, the work is done 186 00:12:43,560 --> 00:12:44,130 ‫for us. 187 00:12:44,130 --> 00:12:48,330 ‫So it really saves us a lot of time and writing code as well. 188 00:12:51,100 --> 00:12:57,280 ‫In a later example, we will see how to use the constructors body in the child class to initialize its 189 00:12:57,280 --> 00:12:58,720 ‫own unique properties. 190 00:12:59,050 --> 00:13:02,620 ‫To just quickly reemphasize the radio class here. 191 00:13:03,550 --> 00:13:05,560 ‫Is our child class. 192 00:13:07,100 --> 00:13:13,880 ‫So the inheriting class and the electrical device is our parent class. 193 00:13:14,240 --> 00:13:16,280 ‫So the base class. 194 00:13:16,910 --> 00:13:19,520 ‫So we are going to inherit. 195 00:13:19,520 --> 00:13:23,120 ‫So our radio inherits from electrical device. 196 00:13:23,600 --> 00:13:25,910 ‫So the child inherits from the parent. 197 00:13:25,940 --> 00:13:31,430 ‫Basically, your parents have a certain DNA and you have the same DNA, but you have a little more to 198 00:13:31,430 --> 00:13:32,090 ‫it, so to speak. 199 00:13:32,090 --> 00:13:34,130 ‫So that's how you could think about it. 200 00:13:34,910 --> 00:13:35,540 ‫All right. 201 00:13:35,540 --> 00:13:37,330 ‫So now a little challenge for you. 202 00:13:37,370 --> 00:13:41,090 ‫Adjust the TV class so that it inherits from electrical device as well. 203 00:13:41,270 --> 00:13:43,070 ‫So pause the video and try that, please. 204 00:13:44,120 --> 00:13:44,780 ‫All right. 205 00:13:44,780 --> 00:13:45,980 ‫I hope you tried it. 206 00:13:45,980 --> 00:13:49,640 ‫So first we need to add colon electrical device. 207 00:13:50,060 --> 00:13:52,250 ‫Then we can get rid of the redundant code. 208 00:13:52,250 --> 00:13:59,450 ‫So the repetitive code, because we have it in our base class already, and this means that we can use 209 00:13:59,450 --> 00:14:01,760 ‫it in our TV class directory as well. 210 00:14:01,910 --> 00:14:12,020 ‫And now we can also adjust this here, saying that we're going to pass the data on to our base class. 211 00:14:12,110 --> 00:14:14,720 ‫And of course, we don't need to set that here as well. 212 00:14:14,720 --> 00:14:20,720 ‫But as I said in the later example, we are going to see how we can still use the body efficiently and 213 00:14:20,720 --> 00:14:22,730 ‫that is going to be basically it. 214 00:14:23,000 --> 00:14:28,820 ‫Now we can just go ahead to our program CSV file and actually check our code here. 215 00:14:28,970 --> 00:14:34,490 ‫And by checking our code, I mean create objects of our radio and test it. 216 00:14:34,490 --> 00:14:37,250 ‫So let's go ahead, create in radio object. 217 00:14:37,550 --> 00:14:42,110 ‫I'm going to call this one my radio and this will be a new radio object. 218 00:14:42,230 --> 00:14:44,300 ‫Now, of course, I need to pass whether it's on. 219 00:14:44,300 --> 00:14:50,720 ‫So I'm going to turn it off at the beginning and I'm going to say it's going to be made by Sony, so 220 00:14:50,720 --> 00:14:52,070 ‫the brand will be Sony. 221 00:14:52,820 --> 00:14:55,550 ‫Now I can access the properties. 222 00:14:55,550 --> 00:15:02,840 ‫You can see here this tool item, the properties of my radio, which is the brand and the is own property 223 00:15:03,410 --> 00:15:06,110 ‫and I can also access IT methods. 224 00:15:06,110 --> 00:15:09,380 ‫So switch on, switch off, listen radio. 225 00:15:09,380 --> 00:15:15,590 ‫And then you can also see that there are some methods that we never created ourselves which are just 226 00:15:15,590 --> 00:15:22,880 ‫there from the get go, because every class inherits from the object class and the object class has 227 00:15:22,880 --> 00:15:28,970 ‫a two string method as well as a get type get hashCode and equals method. 228 00:15:29,420 --> 00:15:35,930 ‫So these methods, they are there for every single class that you are creating in C sharp because basically 229 00:15:36,170 --> 00:15:42,770 ‫we don't see it, but internally it inherits from the object class like so. 230 00:15:42,770 --> 00:15:48,380 ‫So every class inherits from the object class and that's why we have these different methods. 231 00:15:48,560 --> 00:15:51,260 ‫But now let's first of all switch it on. 232 00:15:51,770 --> 00:15:53,150 ‫So here, switch on. 233 00:15:54,410 --> 00:15:59,210 ‫This will switch on our radio and now we can listen to our radio. 234 00:15:59,210 --> 00:16:00,500 ‫So hear my radio. 235 00:16:00,530 --> 00:16:01,610 ‫Dot, listen. 236 00:16:01,610 --> 00:16:02,270 ‫Radio. 237 00:16:03,920 --> 00:16:08,240 ‫Now let's run this and this will allow us to listen to our radio. 238 00:16:09,880 --> 00:16:12,220 ‫So that we are listening to the radio. 239 00:16:12,550 --> 00:16:14,930 ‫So we switch to radio on. 240 00:16:14,950 --> 00:16:18,880 ‫Let's now not switch the radio on and listen to radio. 241 00:16:18,880 --> 00:16:20,920 ‫And it will say radio switched off. 242 00:16:20,920 --> 00:16:22,450 ‫Switch it on first. 243 00:16:23,930 --> 00:16:28,490 ‫All right, so now let's do the same thing with our TV. 244 00:16:28,820 --> 00:16:31,260 ‫Let's go ahead and create a TV object. 245 00:16:31,280 --> 00:16:38,810 ‫I'm going to call this on my TV, which will be a new TV object, and this one will be turned off as 246 00:16:38,810 --> 00:16:39,350 ‫well. 247 00:16:39,350 --> 00:16:41,000 ‫And it will be a Samsung device. 248 00:16:42,630 --> 00:16:50,610 ‫And now let's go ahead and use my TV dot switch on to switch it on. 249 00:16:52,620 --> 00:16:55,770 ‫And then let's call the watch TV method. 250 00:16:57,100 --> 00:16:57,370 ‫Mike. 251 00:16:57,370 --> 00:17:04,210 ‫So now let's run this and we will see that now our TV is turned on and we're watching it while listening 252 00:17:04,210 --> 00:17:05,170 ‫to the radio. 253 00:17:05,200 --> 00:17:06,970 ‫So quite a task there. 254 00:17:06,970 --> 00:17:10,120 ‫But basically our code does what we want it to. 255 00:17:11,760 --> 00:17:16,620 ‫So now you see we call the switch on method for the radio as well as the TV. 256 00:17:16,650 --> 00:17:23,640 ‫Even though if we look at the TV class, it doesn't have this method, so it doesn't have a switch on 257 00:17:23,670 --> 00:17:26,490 ‫to well, switch on or switch off method. 258 00:17:26,580 --> 00:17:31,950 ‫The radio doesn't have those methods either, but that is because they are inheriting from the electrical 259 00:17:31,950 --> 00:17:37,530 ‫device which has those methods switch on and switch off that we can use it. 260 00:17:37,980 --> 00:17:41,370 ‫So basically here we're using the method of the. 261 00:17:42,220 --> 00:17:43,000 ‫Base class. 262 00:17:43,000 --> 00:17:43,790 ‫So here. 263 00:17:43,810 --> 00:17:45,820 ‫Method of base class. 264 00:17:46,720 --> 00:17:51,610 ‫And here we're using the method of child class. 265 00:17:52,800 --> 00:17:57,750 ‫So this switch on method comes from the parent class and the watch TV method is from the child class. 266 00:17:57,750 --> 00:18:03,990 ‫So now we can create the code that is unique to the class, and it's not repetitive, so to speak, 267 00:18:03,990 --> 00:18:06,870 ‫directly in the TV class as well as in the radio class. 268 00:18:06,870 --> 00:18:12,960 ‫But everything that is the same and will be relevant for electrical devices in general is something 269 00:18:12,960 --> 00:18:14,580 ‫that we can create in here. 270 00:18:15,240 --> 00:18:19,920 ‫There is a lot more to inheritance and of course we're going to look into all of that throughout this 271 00:18:19,920 --> 00:18:20,460 ‫chapter. 272 00:18:20,460 --> 00:18:21,990 ‫So see you in the next video.