Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Person {
name: string;
constructor(name: string) {
this.name = name;
}
}
class Employee extends Person {
salary: number;
constructor(name: string, salary: number) {
super(name);
this.salary = salary;
}
getYearlySalary() {
return 12 * this.salary;
}
}
class Manager extends Person {
employees: Employee[];
constructor(name: string, employees: Employee[]) {
super(name);
this.employees = employees;
}
getYearlySalariesOfAllEmployees() {
let salary = 0;
this.employees.forEach(employee => {
salary += employee.getYearlySalary();
});
return salary;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment