子类可以有跟父类中同名的方法,但是会重写父类中的方法,甚至是root class中的方法

/* 
子类可以重写父类中的方法,甚至是root class中的方法,比如NSObeject 的new方法,但是后提示警告如下 Method is expected to return an instance of its class type 'Student', but is declared to return 'void'
*/ #import <Foundation/Foundation.h> @interface Student : NSObject + (void)new; @end @implementation Student + (void)new { NSLog(@"执行了new方法"); } @end int main(int argc, const char * argv[]) { @autoreleasepool { [Student new]; } return 0; }

 

posted @ 2016-03-18 14:54  EricSun  阅读(258)  评论(0编辑  收藏  举报