Hello, I’m wondering if it’s possible to change the default property of a subclass. Specifically, if a parent class has a property with a default value, and I want to create a subclass that will inherit that property, but use a different default value specific to the subclass – is that even possible? I tried to do that with the below code and it’s not working for me.
class Spaceship {
var fuelLevel: Int = 50
func liftOff() {
fuelLevel -= 50
print("We have lift off!")
print("Current fuel level is at: \(fuelLevel)")
}
func addFuel(fuel: Int) {
fuelLevel += fuel
print("Fuel added!")
print("Current fuel leel is at: \(fuelLevel)")
}
func thrust() {
fuelLevel -= 15
print("Rocket is thrusting!")
print("Current fuel level is at: \(fuelLevel)")
}
func cruise() {
fuelLevel -= 5
print("Rocket is cruising!")
print("Current fuel level is at: \(fuelLevel)")
}
}
class UFOShip: Spaceship {
fuelLevel = 25
func float() {
print("The UFO is now floating!")
}
override func cruise() {
fuelLevel -= 2
print("The UFO is now cruising along!")
print("The current fuel level is at \(fuelLevel)")
}
}
var myNewUFO = UFOShip()
myNewUFO.cruise()