0 votes
in TypeScript - JavaScript's Superset by
How do you implement inheritance in TypeScript?

1 Answer

0 votes
by

Inheritance is a mechanism that acquires the properties and behaviors of a class from another class. It is an important aspect of OOPs languages and has the ability which creates new classes from an existing class. The class whose members are inherited is called the base class, and the class that inherits those members is called the derived class.

An Inheritance can be implemented by using the extend keyword. We can understand it by the following example.

class Shape {     

   Area:number     

   constructor(area:number) {     

      this.Area = area    

   }     

}     

class Circle extends Shape {     

   display():void {     

      console.log("Area of the circle: "+this.Area)     

   }     

}    

var obj = new Circle(320);     

obj.display()  //Output: Area of the circle: 320  

Related questions

0 votes
asked Mar 23, 2022 in TypeScript - JavaScript's Superset by sharadyadav1986
0 votes
asked Mar 23, 2022 in TypeScript - JavaScript's Superset by sharadyadav1986
...