class Student {
constructor(name, age, title) {
this.name = name;
this.age = age;
this.title = title;
}
methodVal() {
return `His name is ${this.name}, and his age is ${this.age}`;
}
get getterMethod() {
return `Her name is ${this.name}, age is ${this.age}, & she is a ${this.title}`;
}
}
class Teacher extends Student {
constructor(name, age, title, subject) {
super(name, age, title);
this.subject = subject;
}
}
// Parent class instance
const parentClass = new Student("Mozahedul", 65, "student");
console.log("PARENT CLASS ==> ", parentClass.methodVal());
// Child class instances
const childClass = new Teacher("mofizul", 15, "teacher", "mathematics");
console.log("CHILD CLASS ==> ", childClass);
console.log("CHILD CLASS METHOD ==> ", childClass.methodVal());
console.log("PARENT CLASS GETTER METHOD ==> ", childClass.getterMethod);
Post a Comment