TYPESCRIPT
TypeScript - Class
Create a class "Restaurant" that has
- one public member "menu" to store today's menu list
- a constructor to initialize it, and
- function "list()" that display today's menu list
In list() function, log the menu.
Sample Output:
['dosa','idli','chaat']
Note: Input array is passed in the constructor of the class Restaurant
Solution:
class Restaurant {
public menu: string[];
constructor(theMenu: string[]) {
this.menu = theMenu;
}
list() {
console.log(this.menu);
}
}
let newRestaurantObject = new Restaurant(['dosa','idli','chaat'])
newRestaurantObject.list()
Also check out - TypeScript Inheritance TypeScript Polymorphism
Comments
Post a Comment