SHARE
TWEET

Untitled

a guest Oct 18th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Animal {
  2.   color: string;
  3.   numberOfPaws: number;
  4.  
  5.   constructor(color: string, numberOfPaws: number) {
  6.     this.color = color;
  7.     this.numberOfPaws = numberOfPaws;
  8.   }
  9. }
  10.  
  11. class Cat extends Animal {
  12.   constructor(color: string, numberOfPaws: number) {
  13.     super(color, numberOfPaws);
  14.   }
  15. }
  16.  
  17. class Dog extends Animal {
  18.   constructor(color: string, numberOfPaws: number) {
  19.     super(color, numberOfPaws);
  20.   }
  21. }
  22.  
  23. class Bird extends Animal {
  24.   constructor(color: string, numberOfPaws: number) {
  25.     super(color, numberOfPaws);
  26.   }
  27. }
  28.  
  29. class Fish extends Animal {}
  30.  
  31. class Lombric extends Animal {}
  32.  
  33. function photographAllAnimals(animal: Animal) {
  34.   console.log("Click!");
  35. }
  36.  
  37. function meow(cat: Cat) {
  38.   console.log("Miaouuuu");
  39. }
  40.  
  41. function bark(dog: Dog) {
  42.   console.log("Whoaf whoaf!!");
  43. }
  44.  
  45. function fly(bird: Bird) {
  46.   console.log("I believe I can fly...");
  47. }
  48.  
  49. function swim(fish: Fish) {
  50.   console.log("Oh yeah I can swim!");
  51. }
  52.  
  53. function caress(animal: Animal) {
  54.   if (this.numberOfPaws === 4) {
  55.     console.log("You can caress it");
  56.   } else {
  57.     console.log("Sorry you can't");
  58.   }
  59.  
  60.   function feed(animal: Animal) {
  61.     if (this.color === "black") {
  62.       console.log("Miam!");
  63.     } else {
  64.       console.log("Sorry but you can't feed it");
  65.     }
  66.   }
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top