首页 > 编程语言 > 详细

Swift 中的静态方法继承

时间:2014-11-17 13:55:03      阅读:296      评论:0      收藏:0      [点我收藏+]

Base and Derived Classes:

class BaseClass{
    class func staticMethod(){
        println("BaseClass.staticMethod")
    }
    
    class func staticMethodWithSelfCall(){
        self.staticMethod()
    }
    
    func instanceMethodWithStaticCall(){
        self.dynamicType.staticMethod()
    }
}

class DerivedClass : BaseClass{
    override class func staticMethod(){
        println("DerivedClass.staticMethod")
    }
}

Test Code:

    BaseClass.staticMethod()
    DerivedClass.staticMethod()
    
    BaseClass.staticMethodWithSelfCall()
    DerivedClass.staticMethodWithSelfCall()
    
    BaseClass().instanceMethodWithStaticCall()
    DerivedClass().instanceMethodWithStaticCall()

Output:

BaseClass.staticMethod
DerivedClass.staticMethod
BaseClass.staticMethod
DerivedClass.staticMethod
BaseClass.staticMethod
DerivedClass.staticMethod

 

Swift 中的静态方法继承

原文:http://www.cnblogs.com/zanxiaofeng/p/4103400.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!