Challenge: TypeScript Inheritance
Complete the challenge of implementing inheritance in TypeScript.
We'll cover the following
In this challenge, you are required to implement a class hierarchy for a shape-based application. The application needs to handle various shapes such as circles, squares, and triangles. Each shape has specific properties and behavior. Your goal is to create TypeScript classes that represent these shapes and their interactions.
Requirements
Here are the simplified requirements for this challenge:
Create an abstract
Shape
class with the following properties and methods.Properties:
name: string
(the name of the shape)Methods:
abstract calculateArea(): number
(calculates the area of the shape)
Implement a
Circle
class that extendsShape
with the following properties and methods:Properties:
radius: number
Methods:
calculateArea(): number
(calculates the area of the circle)
Implement a
Square
class that extendsShape
with the following properties and methods:Properties:
sideLength: number
Methods:
calculateArea(): number
(calculates the area of the square)
Implement a
Triangle
class that extendsShape
with the following properties and methods:Properties:
base: number
andheight: number
Methods:
calculateArea(): number
(calculates the area of the triangle)
Example input and output
The following are the example inputs and outputs:
Get hands-on with 1400+ tech skills courses.