typescript how to call a public function from subclass code example

Example 1: ts override method

class Person{
    name:string
 
    eat():void{
        console.log(this.name+" eats when hungry.")
    }
}
 
class Student extends Person{
    // variables
    rollnumber:number;
 
    // constructors
    constructor(rollnumber:number, name1:string){
        super(); // calling Parent's constructor
        this.rollnumber = rollnumber
        this.name = name1
    }
 
    // functions
    displayInformation():void{
        console.log("Name : "+this.name+", Roll Number : "+this.rollnumber)
    }
 
    // overriding super class method
    eat():void{
        console.log(this.name+" eats during break.")
    }
}
 
var student1 = new Student(2, "Rohit")
 
student1.displayInformation()
student1.eat()

Example 2: class inheritance in typescript

// Parent class
class Info {
  protected name: string ;
  constructor(n:string){
    this.name = n ;
  };
  describe(){
    console.log(`Your name is  ${this.name}`);
  }
}

//inherited class (you can overwrite methods of parent class, super is used to
// connect to the parent parameter(s) . )

class Detail extends Info{
  constructor(name:string, public age:number){
    super(name);
  }
  findAge(){
      console.log(`${this.name} age is ${this.age}`)
  }
}

const b = new Detail('jank', 23);
b.describe();
b.findAge();