Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Animal {
- color: string;
- numberOfPaws: number;
- constructor(color: string, numberOfPaws: number) {
- this.color = color;
- this.numberOfPaws = numberOfPaws;
- }
- }
- class Cat extends Animal {
- constructor(color: string, numberOfPaws: number) {
- super(color, numberOfPaws);
- }
- }
- class Dog extends Animal {
- constructor(color: string, numberOfPaws: number) {
- super(color, numberOfPaws);
- }
- }
- class Bird extends Animal {
- constructor(color: string, numberOfPaws: number) {
- super(color, numberOfPaws);
- }
- }
- class Fish extends Animal {}
- class Lombric extends Animal {}
- function photographAllAnimals(animal: Animal) {
- console.log("Click!");
- }
- function meow(cat: Cat) {
- console.log("Miaouuuu");
- }
- function bark(dog: Dog) {
- console.log("Whoaf whoaf!!");
- }
- function fly(bird: Bird) {
- console.log("I believe I can fly...");
- }
- function swim(fish: Fish) {
- console.log("Oh yeah I can swim!");
- }
- function caress(animal: Animal) {
- if (this.numberOfPaws === 4) {
- console.log("You can caress it");
- } else {
- console.log("Sorry you can't");
- }
- function feed(animal: Animal) {
- if (this.color === "black") {
- console.log("Miam!");
- } else {
- console.log("Sorry but you can't feed it");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement