标签:style blog color sp div log bs as nbsp
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
标签:style blog color sp div log bs as nbsp
原文地址:http://www.cnblogs.com/zanxiaofeng/p/4103400.html