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 Car {
2 //field
3 engine:string;
4
5 //constructor
6 constructor(engine:string) {
7 this.engine = engine
8 }
9
10 //function
11 disp():void {
12 console.log("Engine is : "+this.engine)
13 }
14}
1class Animal {
2 move(distanceInMeters: number = 0) {
3 console.log(`Animal moved ${distanceInMeters}m.`);
4 }
5}
6
7class Dog extends Animal {
8 bark() {
9 console.log("Woof! Woof!");
10 }
11}
12
13const dog = new Dog();
14dog.bark();
15dog.move(10);
16dog.bark();Try