Skip to content

Instantly share code, notes, and snippets.

@kusa-mochi
Created September 9, 2018 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kusa-mochi/853cf42cbf03905cd85b7606a8f96831 to your computer and use it in GitHub Desktop.
Save kusa-mochi/853cf42cbf03905cd85b7606a8f96831 to your computer and use it in GitHub Desktop.
class Animal {
constructor(public name: string) { }
move(distanceInMeters: number = 0) {
console.log(`${this.name} moved ${distanceInMeters}m.`);
}
}
class Snake extends Animal {
constructor(name: string) { super(name); }
move(distanceInMeters = 5) {
console.log("Slithering...");
super.move(distanceInMeters);
}
}
class Horse extends Animal {
constructor(name: string) { super(name); }
move(distanceInMeters = 45) {
console.log("Galloping...");
super.move(distanceInMeters);
}
}
let sam = new Snake("Sammy the Python");
let tom: Animal = new Horse("Tommy the Palomino");
sam.move();
tom.move(34);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment