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 254 views
1 answer 250 views
1 answer 297 views
1 answer 246 views
246 views asked Apr 1, 2018 by avibootz
2 answers 511 views
511 views asked Jul 4, 2017 by avibootz
6 answers 626 views
626 views asked Apr 25, 2017 by avibootz
1 answer 285 views
285 views asked May 30, 2016 by avibootz
...