In the following code, why is myRide.drive()
printing a class Car
instead of "Driving at 200"?
class Car {
var topSpeed = 200
func drive() {
print("Driving at \(topSpeed)")
}
}
class Futurecar : Car {
func fly() {
print ("Flying")
}
}
let myRide = Car() // Car
myRide.topSpeed // 200
myRide.drive() // Car
let myNewRide = Futurecar() // Futurecar
myNewRide.topSpeed // 200
myNewRide.drive() // Futurecar
myNewRide.fly() // Futurecar
I understand that the class Futurecar
is inheriting from the car class. Thanks!