1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
//main.m
//10-【掌握】类的声明和实现
//.h为类的声明,.m为类的实现,+表示类方法静态方法,-表示对象方法。.h文件中的方法都是public不能更改的。变量3中访问域:public,protected(子类),private(本类)。
#import <Foundation/Foundation.h>
//声明类
@
interface
Person : NSObject(父类名)
{
//声明属性变量的时候 前面一定要加下划线.
NSString * _name;
int
_age;
float
_weight;
}
//声明方法
- (
void
)eat;
- (
void
)run;
+ (
void
)breath;
@end
//对人类 做一个实现类 要实现哪个类 就在 @implementation 后面 放哪个类的类名.
@implementation Person
//实现方法
- (
void
)eat{
NSLog(
@"吃吃吃吃"
);
}
- (
void
)run{
NSLog(
@"跑跑跑"
);
}
+ (
void
)breath{
NSLog(
@"xxixixixix"
);
}
@end
int
main(
int
argc,
const
char
* argv[]) {
@autoreleasepool {
// insert code here...
NSLog(
@"Hello, World!"
);
}
return
0;
}
|
本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/p/5305524.html,如需转载请自行联系原作者