The following works.
class Parent {
constructor(x) {
this.x = x;
}
present() {
return `I have a ${this.x}`;
}
}
class Child extends Parent {
constructor(x, y) {
super(x);
this.y = y;
}
// different name !!!
show() {
return `${this.present()}, it is a ${this.y}`;
}
}
child = new Child("Tinggu", "Winggu");
console.log(child.present());
However, unlike in Java, methods in the Parent and Child class with the same name don't seem to work.
...
class Child extends Parent {
constructor(x, y) {
super(x);
this.y = y;
}
// same name !!!
present() {
return `${this.present()}, it is a ${this.y}`;
}
}
...
Is there anyway to make this work?