Modern JavaScript
About Lesson

In this JavaScript lesson we are going to talk about JavaScript Class Inheritance, also we will learn that how you can use method overriding in JavaScript, so class inheritance is the mechanism of basing an object or class upon another object or class, retaining similar implementation. Also defined as deriving new classes from existing ones such as super class or base class and then forming them into a hierarchy of classes.

 

 

Now let’s create an example of class inheritance. in this code we have two classes the first one is our Animal class and it is our base class, we have another Dog class that extends from the Animal base class, if you see the Animal class we have a function of speak(). now our Dog class after extending from the Animal class can access to this function.

 

 

 

Also you can do method overriding, for example if you want to change the functionality of the speak() function in your extended class than you can use method overriding.

 

Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.
Exercise Files
No Attachment Found
No Attachment Found