⊗jsOpIhOChM 30 of 60 menu

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:

class 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:

let student = new Student;

Let's set its name using the inherited method, and its year of study using our own method:

student.setName('john'); student.setYear(1);

Let's read his name and year of study:

let name = student.getName(); let year = student.getYear(); console.log(name, year);

In the Employee class, create a salary getter and setter.

Check that both native and inherited methods work in the Employee class.

byenru