#import <Foundation/Foundation.h>
//类的声明 @interface Person : NSObject { @public NSString *_name; NSString *_dog; }
//类的方法 - (void) eat; - (void) run;
@end
//类的实现 @implementation Person
//类的方法的具体实现 - (void) eat{
NSLog(@"%@在吃饭",_name); } - (void) run{ NSLog(@"%@在跑",_dog);
}
@end
int main(int argc, const char * argv[]) { @autoreleasepool {
//定义Person的对象 Person *person = [Person new];
//访问实例变量 person->_name =@"包子"; person->_dog =@"大黄";
//调用方法 [person eat]; [person run];
} return 0; }
|