Typescript - Human Inheritance
Typescript - Restaurant 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', 'idly', 'chat']
Note: Input array is passed in the constructor of the class Restaurant
class Restaurant {
public menu: string[];
constructor(menu: string[]) {
this.menu = menu;
}
list(): void {
console.log(this.menu);
}
}
// Example usage:
const todayMenu = ['dosa', 'idly', 'chat'];
const restaurant = new Restaurant(todayMenu);
// Calling the list method to display today's menu
restaurant.list();
// Example usage:
const todayMenu = ['dosa', 'idly', 'chat'];
const restaurant = new Restaurant(todayMenu);
// Calling the list method to display today's menu
restaurant.list();
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.