Home / Programs / Typescript - Human Inheritance
🚀 Programming Example

Typescript - Human Inheritance

👁 105 Views
💻 Practical Program
📘 Step Learning

📌 Information & Algorithm

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

💻 Program Code

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();

                        

🖥 Program Output

// Example usage:
const todayMenu = ['dosa', 'idly', 'chat'];
const restaurant = new Restaurant(todayMenu);

// Calling the list method to display today's menu
restaurant.list();

                            
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

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.

🔥 Practice suggestion

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.