Page 145

Swift

} } class Rectangle: Circle { var print = 7 override var area: String { return super.area + " is now overridden as \(print)" } }

let rect = Rectangle() rect.radius = 25.0 rect.print = 3 println("Radius \(rect.area)")

class Square: Rectangle { override var radius: Double { didSet { print = Int(radius/5.0)+1 } } }

let sq = Square() sq.radius = 100.0 println("Radius \(sq.area)") When we run the above program using playground, we get the following result: <stdin>:14:18: error: var overrides a 'final' var override var area: String { ^ <stdin>:7:9: note: overridden declaration is here var area: String { ^ <stdin>:12:11: error: inheritance from a final class 'Circle' class Rectangle: Circle { 133

​Quick is really a powerful and intuitive programming language for macOS, iOS, watchOS and tvO...  

...

Advertisement