abstract class Department {
constructor(public name: string) {
}
printName(): void {
console.log("Department name: " + this.name);
}
// must be implemented in derived classes
abstract printMeeting(): void;
}
class AccountingDepartment extends Department {
constructor() {
// constructors in derived classes must call super()
super("Accounting and Auditing");
}
printMeeting(): void {
console.log("The Accounting Department meets each Monday at 10am.");
}
generateReports(): void {
console.log("Generating accounting reports...");
}
}
let department: Department; //ok to create a reference to an abstract type
department = new Department();//error: cannot create an instance of an abstract class
department = new AccountingDepartment();//ok to create and assign a non-abstract subclass
department.printName();
department.printMeeting();
department.generateReports(); //error: method doesn't exist on declared abstract type