1 00:00:00,490 --> 00:00:02,770 So how did you find that fairly easy? 2 00:00:03,070 --> 00:00:06,610 I'm guessing the hard part was figuring out what variables you were going to use. 3 00:00:07,180 --> 00:00:08,170 Well, here's my version. 4 00:00:08,420 --> 00:00:11,350 A class of gadget has keyboard, has SIM card. 5 00:00:12,680 --> 00:00:19,050 So gadget's usually don't have a SIM card and gadgets usually do have a keyboard. 6 00:00:19,700 --> 00:00:22,790 How would we subclass that to define a smartphone? 7 00:00:23,420 --> 00:00:23,780 Well. 8 00:00:25,760 --> 00:00:30,800 We would say smartphone inherits from gadget and we're going to override its initial. 9 00:00:31,340 --> 00:00:37,580 So even though we haven't specified the initialise here, here, we're still going to override it. 10 00:00:37,610 --> 00:00:38,600 We're going to call super. 11 00:00:38,610 --> 00:00:42,800 So it's still initializes everything because look what happens if we leave this out. 12 00:00:44,240 --> 00:00:47,570 Give it a second to catch up, we get Megaera. 13 00:00:49,840 --> 00:00:54,610 And then after it's done what it does, we then set keyboard to false because smartphones don't really 14 00:00:54,610 --> 00:01:00,530 these days or physical keyboard and self-taught has SIM card equal to true. 15 00:01:01,180 --> 00:01:07,690 And then, of course, if we're going to print that out, we could say smartphone object dot. 16 00:01:08,790 --> 00:01:09,480 Has keyboard. 17 00:01:11,310 --> 00:01:12,690 And that will say false. 18 00:01:14,160 --> 00:01:20,850 OK, now it's important to note that and I I should have mentioned this before smartphone. 19 00:01:22,750 --> 00:01:23,620 Smartphone. 20 00:01:24,950 --> 00:01:34,040 Are all different objects, so if I change keyboard on this one, it has absolutely no effect on this 21 00:01:34,040 --> 00:01:35,090 one or this one. 22 00:01:36,050 --> 00:01:42,650 Every object has its own copy of the variables and the functionality inside of it, so they each have 23 00:01:42,650 --> 00:01:49,520 their own state, right state represents what the data looks like at any one point in time inside the 24 00:01:49,520 --> 00:01:49,910 object. 25 00:01:51,440 --> 00:01:55,940 So I should have really mentioned that, and it doesn't matter how many times you create it, the state 26 00:01:55,940 --> 00:01:56,690 is always the same. 27 00:01:57,500 --> 00:02:01,800 The state is always inside, contained inside of that object. 28 00:02:02,600 --> 00:02:05,960 Now, some languages allow you to use what are called static variables. 29 00:02:07,880 --> 00:02:10,580 I would say avoid static variables like the plague. 30 00:02:10,590 --> 00:02:16,730 So if we're in a smartphone, if you're in C sharp, you'd have a static var. 31 00:02:19,790 --> 00:02:21,060 What else is on a smartphone? 32 00:02:21,080 --> 00:02:21,500 I don't know. 33 00:02:22,960 --> 00:02:24,340 Battery equals true. 34 00:02:26,420 --> 00:02:29,600 OK, now it's just going to work on this. 35 00:02:30,550 --> 00:02:38,350 Apparently, it was just a random guess that in that case for this this is going to be the same for 36 00:02:38,350 --> 00:02:40,090 all of these bright. 37 00:02:41,190 --> 00:02:47,880 Even if you try to change it, but if I try and take a battery, I can't access it. 38 00:02:49,090 --> 00:02:49,800 Why is that? 39 00:02:50,140 --> 00:02:57,400 Because it has nothing to do with the object or instance we created, it has to do with the original 40 00:02:58,330 --> 00:03:05,920 class so I can access it if I don't put the brackets here to make it into an object. 41 00:03:06,190 --> 00:03:08,680 And I'm just looking at the class. 42 00:03:09,670 --> 00:03:11,200 OK, so that's how that works. 43 00:03:11,740 --> 00:03:16,630 Avoid static's really, really, really, really avoid static's if you can. 44 00:03:16,810 --> 00:03:23,320 Again, some situations where you have to use them or put my hand up and admit this, you're being lazy, 45 00:03:23,470 --> 00:03:29,410 you just throw in a static here and there, but for the most part and please, please avoid them. 46 00:03:29,860 --> 00:03:30,210 All right. 47 00:03:30,550 --> 00:03:32,140 That's inheritance done.