【发布时间】:2016-02-28 12:50:54
【问题描述】:
所以我有以下超类:
class Vehicle {
private var _maxSpeed: Int = 100
var maxSpeed: Int {
get {
return _maxSpeed
}
var tooFast: Bool {
get {
if maxSpeed >= 140 {
return false
} else {
return true
}
}
}
}
另外,我有一些子类,我想在其中覆盖 maxSpeed... 每个示例:
class SuperCar: Vehicle {
//override the maxspeed...
}
但是我应该如何处理呢?还是只有在我们不将其设为私有时才有可能?我试图将私密部分扔出窗外,但效果不佳...
class Vehicle {
var maxSpeed: Int = 100
var tooFast: Bool {
get {
if maxSpeed >= 140 {
return false
} else {
return true
}
}
}
}
class SuperCar: Vehicle {
// override the maxSpeed...
override var maxSpeed: Int = 200
// Will not work...
}
【问题讨论】:
标签: swift class subclass private superclass