How to use abstract class with abstract property in TypeScript

1 Answer

0 votes
abstract class Person {
    abstract pName: string;

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

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

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



  
  
      
/*
      
run:
      
"Professor Albus Dumbledore" 
     
*/

 



answered Oct 25, 2021 by avibootz

Related questions

1 answer 172 views
1 answer 163 views
1 answer 202 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
...