1class Info {
2 private name: string ;
3 constructor(n:string){
4 this.name = n ;
5 };
6 describe(){
7 console.log(`Your name is ${this.name}`);
8 }
9}
10
11const a = new Info('joyous');
12a.describe();
1class Greeter {
2 greeting: string;
3
4 constructor(message: string) {
5 this.greeting = message;
6 }
7
8 greet() {
9 return "Hello, " + this.greeting;
10 }}
11
12let greeter = new Greeter("world");Try
1class Greeter { greeting: string;
2 constructor(message: string) { this.greeting = message; }
3 greet() { return "Hello, " + this.greeting; }}
4let greeter = new Greeter("world");Try