How to use abstract class in TypeScript

1 Answer

0 votes
abstract class Person {
    pName: string;
    
    constructor(name: string) {
        this.pName = name;
    }

    display(): void {
        console.log('display(): void { - ' + this.pName);
    }

    abstract test(string: string): void;
}

class Employee extends Person { 
    eID: number;
    
    constructor(name: string, ID: number) { 
        super(name); 
        this.eID = ID;
    }

    test(name: string): void { 
        console.log('test(name: string): void { - ' + name)
    }
}

let emp: Person = new Employee('Professor Albus Dumbledore', 83736);
emp.display(); 

emp.test('R2D2');


    
      
   
  
      
/*
      
run:
      
"display(): void { - Professor Albus Dumbledore" 
"test(name: string): void { - R2D2" 
     
*/

 



answered Oct 25, 2021 by avibootz

Related questions

1 answer 192 views
1 answer 202 views
1 answer 163 views
1 answer 160 views
160 views asked Apr 1, 2018 by avibootz
2 answers 375 views
375 views asked Jul 4, 2017 by avibootz
6 answers 367 views
367 views asked Apr 25, 2017 by avibootz
1 answer 191 views
191 views asked May 30, 2016 by avibootz
...