1abstract class Person {
2 name: string;
3
4 constructor(name: string) {
5 this.name = name;
6 }
7
8 display(): void{
9 console.log(this.name);
10 }
11
12 abstract find(string): Person;
13}
14
15class Employee extends Person {
16 empCode: number;
17
18 constructor(name: string, code: number) {
19 super(name); // must call super()
20 this.empCode = code;
21 }
22
23 find(name:string): Person {
24 // execute AJAX request to find an employee from a db
25 return new Employee(name, 1);
26 }
27}
28
29let emp: Person = new Employee("James", 100);
30emp.display(); //James
31
32let emp2: Person = emp.find('Steve');
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();
1abstract class Department {
2 constructor(public name: string) {}
3
4 printName(): void {
5 console.log("Department name: " + this.name);
6 }
7
8 abstract printMeeting(): void; // must be implemented in derived classes
9}
10
11class AccountingDepartment extends Department {
12 constructor() {
13 super("Accounting and Auditing"); // constructors in derived classes must call super()
14 }
15
16 printMeeting(): void {
17 console.log("The Accounting Department meets each Monday at 10am.");
18 }
19
20 generateReports(): void {
21 console.log("Generating accounting reports...");
22 }
23}
24
25let department: Department; // ok to create a reference to an abstract type
26department = new Department(); // error: cannot create an instance of an abstract class
27Cannot create an instance of an abstract class.2511Cannot create an instance of an abstract class.department = new AccountingDepartment(); // ok to create and assign a non-abstract subclass
28department.printName();
29department.printMeeting();
30department.generateReports();
31Property 'generateReports' does not exist on type 'Department'.2339Property 'generateReports' does not exist on type 'Department'.Try
1abstract class Animal {
2 abstract makeSound(): void;
3
4 move(): void {
5 console.log("roaming the earth...");
6 }
7}Try