Skip to content

Commit d8aa8bb

Browse files
authored
Create inheritance.ts
1 parent 16062ba commit d8aa8bb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

inheritance.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Animal {
2+
name: string;
3+
constructor(name: string) {
4+
this.name = name;
5+
}
6+
speak(): void {
7+
console.log(`${this.name} makes a noise.`);
8+
}
9+
}
10+
11+
class Dog extends Animal {
12+
constructor(name: string) {
13+
super(name);
14+
}
15+
speak(): void {
16+
console.log(`${this.name} barks.`);
17+
}
18+
}
19+
20+
let dog = new Dog("Fido");
21+
dog.speak();

0 commit comments

Comments
 (0)