import Foundation
println("Hello, World!")
class Animal{
func jump()->String{
return "Animal Jump"
}
}
class Cat:Animal{
override func jump() -> String {
return "Cat Jump"
}
}
class Mouse:Animal{
override func jump() -> String {
return super.jump()+" And Mouse Jump"
}
}
class Dog{
func jump() -> String {
return "Dog Jump"
}
}
func outResult(result:Animal){
var retstr=result.jump()
println("The Result is \(retstr)")
}
outResult(Animal())
outResult(Cat())
outResult(Mouse())
//outResult(Dog()) 错误
结果
Hello, World!
The Result is Animal Jump
The Result is Cat Jump
The Result is Animal Jump And Mouse Jump
Program ended with exit code: 0