Advertisement
NeverRIEght

Swift Checkpoint 7

Aug 18th, 2022 (edited)
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.05 KB | Source Code | 0 0
  1. import Foundation
  2.  
  3. class Animal {
  4.     var legs: Int
  5.  
  6.     init(legs: Int) {
  7.         self.legs = legs
  8.     }
  9. }
  10.  
  11. class Cat: Animal {
  12.    
  13.     var isTame = false
  14.  
  15.     func speak() {
  16.         print("Meow!")
  17.     }
  18.  
  19.     init(legs: Int, isTame: Bool)
  20.     {
  21.         self.isTame = isTame
  22.         super.init(legs: legs)
  23.     }
  24.  
  25. }
  26.  
  27. class Persian: Cat {
  28.     override func speak() {
  29.         print("Meooooww!")
  30.     }
  31. }
  32.  
  33. class Lion: Cat {
  34.     override func speak() {
  35.         print("Mew?")
  36.     }
  37. }
  38.  
  39. class Dog: Animal {
  40.     func speak() {
  41.         print("Woof!")
  42.     }
  43. }
  44.  
  45. class Corgi: Dog {
  46.     override func speak() {
  47.         print("Woooooooof!")
  48.     }
  49. }
  50.  
  51. class Poodle: Dog {
  52.     override func speak() {
  53.         print("Wof?")
  54.     }
  55. }
  56.  
  57. var cat1 = Cat(legs: 1, isTame: false)
  58. cat1.speak()
  59.  
  60. var cat2 = Persian(legs: 2, isTame: false)
  61. cat2.speak()
  62.  
  63. var cat3 = Lion(legs: 3, isTame: false)
  64. cat3.speak()
  65.  
  66. var dog1 = Dog(legs: 1)
  67. dog1.speak()
  68.  
  69. var dog2 = Corgi(legs: 2)
  70. dog2.speak()
  71.  
  72. var dog3 = Poodle(legs: 3)
  73. dog3.speak()
  74.  
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement