How to use class inheritance in TypeScript

1 Answer

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

class Employee extends Person {
    eID: number;
    
    constructor(ID: number, name:string) {
        super(name);
        this.eID = ID;
    }
    
    display = () => console.log(this.eID + ' ' + this.pName)

    getSalary() : number {
        return 18950;
    }
}

let emp = new Employee(837369, 'Professor Albus Dumbledore');
 
emp.display();

console.log(emp.getSalary()); 


    
 

    
/*
    
run:
    
"837369 Professor Albus Dumbledore" 
18950 
   
*/

 



answered Oct 25, 2021 by avibootz

Related questions

...