//Inheritance, override, final
class Vehicle{
var totalVehicles : Int = 0
var desc:String {
return "totalVehicles : \(totalVehicles)."
}
}
class Bycle: Vehicle {
override init(){
super.init()
self.totalVehicles = 2
}
override var desc : String {
return super.desc + ", in bycle"
}
final func noOverrideMethod(){
print("final keyword mean this cannot be allowed to override any more")
}
}
class Bycle4Wheels : Bycle {
override init(){
super.init()
self.totalVehicles = 4
}
override var desc : String {
return super.desc + " with 4 wheels "
}
}
var b = Bycle()
print( b.desc)
b.noOverrideMethod()
var f = Bycle4Wheels()
print( f.desc)
2017년 2월 18일 토요일
Swift Inheritance, override, final
//Inheritance, override, final
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기