⊗jsOpIhInr 28 of 60 menu

Class Inheritance in OOP in JavaScript

One class can inherit from another class, borrowing its methods and properties. This is useful when two classes are very similar. For example, we can have a class User, and also Student, which has the same properties and methods, but also adds its own. In this case, it would be convenient for the student to inherit the parent's duplicate methods. Let's see how this is done.

Let's say we have a class User, which will be a parent:

class User { }

Let us also have a class with a student, which will be a child:

class Student { }

Let's make the child class inherit the methods and properties of its parent. This is done using the extends keyword property:

class Student extends User { }

Make class Employee inherit from class User.

plenbytruzc