Simple Javascript Inheritance Problem

Joined
Nov 7, 2023
Messages
1
Reaction score
0
Hey guys, so I had a question.
My base class 'Home' has the uponEntry() method of '~Ambient homely sounds~' . I made the child classes 'Mother' and 'Father' inherit the super.uponEntry() method. Now the subclasses 'Daughter' and 'Son' of the Mother and Father class are supposed to inherit all the methods and variables in their parent classes without me having to define super.UponEntry() again, if i'm not mistaken. However, the output does not show the '~Ambient homely sounds~'. What am I doing wrong or is there something I'm missing?

Thanks.


Code:
class House {
uponEntry() {
console.log("~Ambient homely sounds~");
}
}

class Father extends House {
uponEntry() {
super.uponEntry();
console.log("Masculine Voice:");
}
}

class Mother extends House {
uponEntry() {
super.uponEntry();
console.log("Feminine Voice:");
}
}

class Son extends Father {
uponEntry() {
console.log("I GOT INTO A FIGHT WITH MY FRIEND!");
}
}

class Daughter extends Mother {
uponEntry() {
console.log("OMG MY BOYFRIEND CHEATED ON ME!");
}
}

var Timmy = new Son();
Timmy.uponEntry();

var Lucy = new Daughter();
Lucy.uponEntry();
 

Members online

No members online now.

Forum statistics

Threads
473,821
Messages
2,569,725
Members
45,511
Latest member
Osiris-Team

Latest Threads

Top