1 00:00:00,890 --> 00:00:05,270 Now that we've got a better idea of how fields work inside of a class let's discuss how they work when 2 00:00:05,270 --> 00:00:10,280 we are dealing with inheritance as we are with our class car down here. 3 00:00:10,360 --> 00:00:13,880 I'm going to uncommon everything in the bottom half this file right here and as soon as I do you'll 4 00:00:13,880 --> 00:00:17,600 notice that we get an ear around the new car called right here. 5 00:00:17,660 --> 00:00:22,080 So here's the issue our class car extends Vehicle. 6 00:00:22,080 --> 00:00:27,970 Anytime we create an instance of something that is a vehicle we have to provide it a color or a string 7 00:00:27,980 --> 00:00:30,050 to use as the color. 8 00:00:30,050 --> 00:00:34,940 So the reason we're seeing this area here is that we have to pass in a string that will serve as the 9 00:00:34,940 --> 00:00:39,470 color so we could fix up this area by putting a string in like red like so. 10 00:00:39,490 --> 00:00:42,420 And as soon as we do that the air goes away. 11 00:00:42,600 --> 00:00:49,040 I want to show you something interesting right now our class car does not have a constructor function. 12 00:00:49,040 --> 00:00:54,230 That means that whenever we try to create an instance of car typescript is going to automatically call 13 00:00:54,230 --> 00:00:58,130 the constructor in the parent function right here. 14 00:00:58,130 --> 00:01:03,260 So even though you don't see any reference to it whenever we create this car right here the constructor 15 00:01:03,260 --> 00:01:08,070 in the parent is being called for us automatically and that's why we have to pass in that string. 16 00:01:08,280 --> 00:01:13,560 Things are gonna be just a little bit different if we define the constructor inside of class car as 17 00:01:13,560 --> 00:01:16,540 well so let's try that right now. 18 00:01:16,710 --> 00:01:20,700 I'm going to define the constructor function side of car and I'm going to say that this thing is going 19 00:01:20,700 --> 00:01:25,210 to have its own property like let's say public wheels. 20 00:01:25,210 --> 00:01:29,520 And this will be maybe like the number of wheels that a car has it's going to annotate with the type 21 00:01:29,640 --> 00:01:33,910 of number like so as soon as I define this constructor. 22 00:01:33,920 --> 00:01:36,070 You'll notice nasty air inside of here. 23 00:01:36,260 --> 00:01:39,890 And if I hover over it it says that the derived class must contain a super. 24 00:01:39,890 --> 00:01:46,580 Call the word super right here is a reference to these superclass or the parent class of car which is 25 00:01:46,580 --> 00:01:51,890 vehicle so whenever we call the constructor of a child class we are required to call the constructor 26 00:01:51,890 --> 00:01:54,940 method of the parent as well to do so. 27 00:01:54,940 --> 00:02:01,010 All we have to do is call super like so as soon as we do so we're still going to see an error here. 28 00:02:01,700 --> 00:02:07,040 So super right here is a reference to the constructor method in the parent. 29 00:02:07,070 --> 00:02:13,130 And once again the constructor in the parent wants us to pass in a string so we can make this go away 30 00:02:13,130 --> 00:02:16,100 once again by putting in some hardcoded string like so. 31 00:02:16,310 --> 00:02:17,750 But chances are we don't want to do that. 32 00:02:17,750 --> 00:02:24,410 Chances are we want to have the color still come in as an argument to our car when we create it. 33 00:02:24,500 --> 00:02:31,080 So maybe we should take in a second argument to the constructor function that we'll call color and it's 34 00:02:31,080 --> 00:02:33,050 supposed to be a string like so. 35 00:02:33,150 --> 00:02:36,150 Notice how I did not put the public key word on here. 36 00:02:36,150 --> 00:02:42,480 I didn't put public on because we do not want to reassign or create a new field in CAR OF COLOR THE 37 00:02:42,510 --> 00:02:45,100 FIELD color belongs to vehicle. 38 00:02:45,160 --> 00:02:49,130 So that's why I did not put on the modifier of public. 39 00:02:49,140 --> 00:02:53,970 So now when we call the parent class constructor through these super call right here we're not going 40 00:02:53,970 --> 00:02:55,450 to pass in a hard coded red. 41 00:02:55,460 --> 00:03:00,890 Instead we could pass on the color if we now go back down to the bottom of the file once more you'll 42 00:03:00,890 --> 00:03:03,230 see it we've got an error down here again. 43 00:03:03,290 --> 00:03:08,630 So now we are saying that our constructor for car has to be given a number of wheels as the first argument 44 00:03:08,870 --> 00:03:11,180 and a second argument of a string. 45 00:03:11,180 --> 00:03:14,710 So we can fix up this area by putting in four wheels as the first argument. 46 00:03:14,720 --> 00:03:18,920 Now the second argument is going to be a string which is going to pass on through the constructor right 47 00:03:18,920 --> 00:03:22,030 here into the parent constructor of vehicle. 48 00:03:22,340 --> 00:03:24,230 And that's pretty much it. 49 00:03:24,250 --> 00:03:26,890 Now I know we're going through this class stuff really quickly. 50 00:03:26,890 --> 00:03:31,150 The reason we're going through it so quickly is that basically all the projects we're going to work 51 00:03:31,150 --> 00:03:37,930 on in this course are 100 percent focused on using classes to represent logic inside of application. 52 00:03:37,930 --> 00:03:42,070 So really I'm just showing you all this class stuff right now to get you used to some of the very basic 53 00:03:42,070 --> 00:03:43,020 syntax. 54 00:03:43,170 --> 00:03:47,620 And we're going to really repeat all these different rules that we're going over in great detail throughout 55 00:03:47,710 --> 00:03:49,830 all these applications we go through. 56 00:03:49,900 --> 00:03:52,730 So hopefully you're just absorbing a little bit of the syntax here. 57 00:03:52,780 --> 00:03:55,740 That's really the only expectation I have. 58 00:03:55,800 --> 00:03:59,360 Now having said all that this is really all we wanted to learn about classes. 59 00:03:59,370 --> 00:04:05,790 So we've taken a look at methods constructors basic inheritance super calls modifiers. 60 00:04:05,790 --> 00:04:08,260 That's pretty much it the whole ballgame. 61 00:04:08,280 --> 00:04:09,750 Let's have a quick pause right here. 62 00:04:09,750 --> 00:04:14,310 We're going to do a wrap up on classes in the next video and we'll start working on some really interesting 63 00:04:14,340 --> 00:04:15,130 applications. 64 00:04:15,150 --> 00:04:17,170 So I'll see you in just a minute.