Inheritance
class Person{
constructor(name,age){
console.log("Person Class constructor")
this.name=name;
this.age=age;
}
talk(){
console.log(`Hi! I am ${this.name}`);
}
}
class Student extends Person{
constructor(name,age,marks){
console.log("Student class constructor");
super(name,age);
this.marks=marks;
}
}
class Teacher extends Person{
constructor(name,age,subject){
console.log("Teacher class constructor");
super(name,age);
this.subject=subject;
}
}
let stud1=new Student("abhi",21,97);

Comments
Post a Comment