Swift 5.1: Inheritance Cheat Sheet

class Student: Person {
  var numberOfExams: Int = 0

  // Override isHappy computed property 
  //providing additional logic
  override var isHappy: Bool {
  numberOfLaughs > 0 && numberOfExams > 2
  }
}

let ray = Student(name: "Ray")
ray.numberOfExams = 4
ray. Laugh()
let happy = ray.isHappy
// Mark Child as final to prevent subclassing
final class Child: Person { }

Leave a Reply

Your email address will not be published. Required fields are marked *