I am working on a code where I need to define a class called programmer
that inherits from the employee
class.
The employee
class constructor should have 4 parameters, and the programmer
class constructor needs to have 5 parameters - 4 from the employee class and one specifically for the programmer class.
What is the best way to achieve this?
class employee {
private id: string;
private name: string;
private department: string;
private salary: number;
constructor(id: string , name: string , department: string , salary: number) {
this.id = id;
this.name = name;
this.department = department;
this.salary = salary;
}
speak() {
console.log(`ID = ${this.id} , Name = ${this.name} , Department = ${this.department} , Salary = ${this.salary}`);
}
}
class programmer extends employee {
private programmingLang: string;
constructor() {
super();
}
speak() {
super.speak() , console.log(` , Programming Language = ${this.programmingLang}`);
}
}