TypeScript use the same concepts of OOP for creating the classes, Just like we create classes in Java, C# or any other OOP programming languages.
We can define a class in typescript by the keyword class.
Lets create a class User below:
We can define a class in typescript by the keyword class.
Lets create a class User below:
class User{
//instance variables
name: string;
age : number;
//default constructor
constructor(){
}
//parameterized constructor
constructor(name: string, age: string){
this.name = name;
this.age = age;
}
//methods
getAge(){
return this.age;
}
getName(){
return this.name;
}
}
No comments
Post your comment.