Descendant Methods in OOP in JavaScript
A descendant class can have its own methods. For example, let's add a getter and setter for our student's year of study:
javascriptclass Student extends User {
setYear(year) {
this.year = year;
}
getYear() {
return this.year;
}
}
The child class will have both its private methods and inherited ones available. Let's check. Let's create an object of the class:
javascriptlet student = new Student;
Let's set its name using the inherited method, and its year of study using our own method:
javascriptstudent.setName('john');
student.setYear(1);
Let's read his name and year of study:
javascriptlet name = student.getName();
let year = student.getYear();
console.log(name, year);
Задание 1
In the Employee class, create a salary getter and setter.
Задание 2
Check that both native and inherited methods work in the Employee class.