Overriding Method or Property javascript
// parent class
class Person {
constructor(name) {
this.name = name;
this.occupation = "unemployed";
}
greet() {
console.log(`Hello ${this.name}.`);
}
}
// inheriting parent class
class Student extends Person {
constructor(name) {
// call the super class constructor and pass in the name parameter
super(name);
// Overriding an occupation property
this.occupation = 'Student';
}
// overriding Person's method
greet() {
console.log(`Hello student ${this.name}.`);
console.log('occupation: ' + this.occupation);
}
}
let p = new Student('Jack');
p.greet();