OC3

it2024-10-13  17

// // Student.h // OC3_协议关键字 // // Created by zhangxueming on 15/6/24. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import <Foundation/Foundation.h> #import "Programmer.h" @interface Student : NSObject <Programmer> @end // // Student.m // OC3_协议关键字 // // Created by zhangxueming on 15/6/24. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import "Student.h" @implementation Student - (void)writeCode { NSLog(@"writing..."); } - (void)debugCode { NSLog(@"debug..."); } - (void)report { NSLog(@"report"); } @end // // Programmer.h // OC3_协议关键字 // // Created by zhangxueming on 15/6/24. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import <Foundation/Foundation.h> @protocol Programmer <NSObject> @required//必须实现的方法(缺省) - (void)writeCode; - (void)debugCode; - (void)report; @optional//可选实现的方法 - (void)eat; - (void)drink; @end // // main.m // OC3_协议关键字 // // Created by zhangxueming on 15/6/24. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import <Foundation/Foundation.h> #import "Student.h" int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... //NSLog(@"Hello, World!"); Student *xiaoHua = [[Student alloc] init]; [xiaoHua report]; //[xiaoHua eat]; } return 0; }

 

转载于:https://www.cnblogs.com/0515offer/p/4598476.html

相关资源:SFF-8472协议中文版
最新回复(0)