面向对象的swift例子


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

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭