O'Reilly logo

Swift 3 ObjectOriented Programming - Second Edition by Gastón C. Hillar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Declaring subclasses that inherit the conformance to protocols

We have an Animal class that conforms to both the AnimalProtocol and Equatable protocols. Now, we will create a subclass of Animal, a Dog class, which overrides the string computed properties defined in the Animal class to provide the appropriate values for a dog. The code file for the sample is included in the swift_3_oop_chapter_06_03 folder:

    open class Dog: Animal { 
      open override var spelledSound1: String { 
        get { 
          return "Woof" 
        } 
      } 
     
      open override var spelledSound2: String { 
        get { 
          return "Wooooof" 
        } 
      } 
     
      open override var spelledSound3: String { 
        get { 
          return "Grr" 
        } 
      } 
     
      open override var danceCharacters: String { 
        get { 
          return "/-\\ \\-\\ /-/" 
        } 
      } 
    } 

With just a few additional lines of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required