- #import <Foundation/Foundation.h>
- @interface Person : NSObject
- {
- @public
- int age;
- int weight;
- char *name;
- }
- - (void)walk;
- - (void)eat;
- @end
- @implementation Person
- - (void)walk
- {
- NSLog(@"%d岁,%d公斤的%s去火星了",age,weight,name);
- }
- - (void)eat
- {
- NSLog(@"%d岁,%d公斤的%s吃粑粑了",age,weight,name);
- }
- @end
- int main()
- {
- Person *p=[Person new];
- p->age=24;
- p->weight=80;
- p->name="狗蛋儿";
-
- [p walk];
- [p eat];
-
- return 0;
- }
复制代码 |