Inheritance of public methods in OOP in JavaScript
The child class inherits all public methods of the parents. Let's look at an example. Let's say we have a class with the following methods:
class User {
setName(name) {
this.name = name;
}
getName() {
return this.name;
}
}
Let the following class inherit from this class:
class Student extends User {
}
Let's check that the methods are inherited. Let's create a new object with a student:
let student = new Student;
Let's set its name using the inherited method:
student.setName('john');
Let's read its name using the inherited method:
let name = student.getName();
console.log(name);
Check that your Employee class inherits methods from the User class.