// ** ** ** Inheritance ** ** **
class Vehicle {
var currentSpeed = 0.0
var description: String{
return "travelling at \(currentSpeed) kilometers per hour"
}
func makeNoice(){
print("Di Di Di")
}
subscript(index:Int)->Double{
get{
return currentSpeed*1.4
}
}
}
class Bike : Vehicle {
var Speedy = false
}
var bought = Bike()
bought.currentSpeed = 100
print(bought.description)
// * when you override superclass property,method,subscript, put override
// you can access superclass methods/property/subscript:
// via super.someproperty, super.someMethod() or super[index]
class Tuolaji : Vehicle {
override func makeNoice() {
print("ba ba ba")
}
override var description: String{
return "what is that running at speed of \(currentSpeed)"
}
override var currentSpeed: Double{
willSet{
print("damn it are you going to set speed!?")
}
}
override subscript(index:Int)->Double{
return currentSpeed*1.41
}
}