Hello in this JavaScript programming tutorial I am going to show you class inheritance. So class inheritance works similar in the way you know inheritance than it does in biology in humans where you know child come from mother and father and you know, inherit certain gene certain traits from your parents. Unlike, you know, genetic inheritance it's not kind of a free for all and you know, it's hard to predict exactly what you're you know, inherit, you know exactly what you're going to hear it in terms of classes you specify this. Okay, so class inheritance, we have this class right here called Boy, you know, what are the classes now what's the car with the bike, the boat vehicles. Now let's create a vehicle class to class. Cool, like so.
And let's go a step further. This conceptual in Here we will add a constructor into any of these, we'll just leave it like this. So okay, that is cool. Let's create a function here. Let's just call this vehicle funk. And we'll just print something like console.
Log. Okay. Now, if we want color and nothing boy inherit from the vehicle class at the end here, the keyword extends the name of the class or copy and paste this up in the copy, paste it. Now if you run it, let's see what we have. Okay, so the first thing was Fine for this one is messing up. Because remember, we don't have a, you know, a different constructor for bike, it's still using the same one vehicle class.
So we need to specify some value. So the the initial X and Y coordinate on 00. Almost like the central graph, we know we got 00. This is a constructor, but haven't looked at this before. That's a good point. obj I think he did empty like there's nothing in here.
Oh, let's see if I do vehicle form. Save that. Refresh. Boom, there we go. This function is from the vehicle class, and as an extra test only to do the same but with the core object and you'll see that we are able to access all of the variables, the methods, the properties of the template, not what's called parent and child classes, and an extra one I want you to do is go even a step further create another class that inherits from One of these classes, and there'll be a grandfather parent child in heritance. And you know, that's it for class inheritance, nothing more to it than that.
You can obviously have more variables and functions with complex functionality that accepts parameters to maybe you know, compute something returns a value doesn't really matter what you do. As long as you understand this is how inheritance works. We have a parent class, these two classes are inheriting from me, I literally have nothing on its own. Yeah, the constructor is there to do some things store, you know, a couple of variables, console as these three lines and then we have a function called vehicle. So that's it class inheritance. If you have any questions, feel free to drop me a message.
The GitHub link will be provided as well as all the source code and I look forward to seeing you in the next video.