Which of the following is the correct way to define an interface in TypeScript?A)interface Person { name: string; age: number;}B)interface Person { name: string; age: string;}C)interface Person { name: number; age: number;}D)interface Person { name: number; age: string;}
Question
Which of the following is the correct way to define an interface in TypeScript?A)interface Person { name: string; age: number;}B)interface Person { name: string; age: string;}C)interface Person { name: number; age: number;}D)interface Person { name: number; age: string;}
Solution
The correct way to define an interface in TypeScript is:
A) interface Person { name: string; age: number; }
This is because in TypeScript, the 'string' data type is used for textual data and the 'number' data type is used for numerical data. In the given interface 'Person', 'name' is more likely to be a string (textual data) and 'age' is more likely to be a number (numerical data). Therefore, option A is the correct way to define the interface.
Similar Questions
What are abstract classes and interfaces in TypeScript?
t answerWhat type of variable can be defined in an interface?
Select the correct answerWhich of the following is the correct way of implementing an interface A by class B?Optionsclass B implements A{}class B extends A{}class B imports A{}None of the mentioned
Which of the following statements about interfaces in Java is correct? Select one: Interfaces cannot inherit from another interface. Using the keyword "extends," inheritance relationships can be defined both between classes and between interfaces. Using the keyword "implements," inheritance relationships can be defined both between classes and between interfaces. Interfaces can inherit only from one other interface.
The following TypeScript code has an error. Can you identify and correct it?class Animal { constructor(public name: string) {}}let dog = new Animal();console.log(dog.name);What is the error, and how would you correct it?
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.