- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
class Animal {
name: string;
constructor(name: string) {
this.name = name;
}
speak() {
print(`${this.name} makes a noise.`);
}
}
class Dog extends Animal {
constructor(name: string) {
super(name); // call the super class constructor and pass in the name parameter
}
speak() {
print(`${this.name} barks.`);
}
}
function main() {
let d = new Dog("Mitzie");
d.speak(); // Mitzie barks.
print(d.name);
}