class Transpotation {
var petrol: Int = 10
func drive() {
if petrol == 0 {
self.addPetrol()
}
}
func addPetrol() {
petrol += 10
}
}
class Car: Transpotation {
var tyre: Int
override func drive() {
super.drive()
print("在路上行驶10km")
self.petrol -= 1
}
init(tyrecount: Int){
tyre = tyrecount
}
}
class Boat:Transpotation {
var floor: Int
override func drive() {
super.drive()
print("在海上行驶 50 km")
self.petrol -= 2
}
init(floorCount: Int) {
floor = floorCount
}
}
class Airplane: Transpotation {
var height: Int
override func drive() {
super.drive()
print("在天上行驶 100km")
self.petrol -= 5
}
init(height: Int) {
self.height = height
}
}
var car = Car(tyrecount: 4)
var boat = Boat(floorCount: 3)
var plane = Airplane(height: 3000)
car.drive()
boat.drive()
plane.drive()
class Shape {
final var center: (Double,Double)
init(){
center = (0, 0)
}
}
final class Shape1 {
final var center: (Double,Double)
init(){
center = (0, 0)
}
}