类方法与对象方法

 1 //
 2 //  main.m
 3 //  OC中的对象方法
 4 //
 5 //  Created by 李鑫 on 2017/2/20.
 6 //  Copyright © 2017年 CCSU. All rights reserved.
 7 //
 8 
 9 #import <Foundation/Foundation.h>
10 @interface StudyRoom : NSObject
11 {
12     @public
13     int _peopleNum;
14     //  -(void)CloseRoom;  -----对象方法在这里生命是错的,应该在打括号外面
15     
16 }
17 -(void)closeRoom;//用驼峰命名法
18 -(void)CloseRoomWorningWithPeople:(char *)people andWoring:(char *)Woring;
19 +(void)openDoorWithAdmin:(char *)admin;//类方法用“+” 直接用类调用,效率高一般用于工具方法
20 @end
21 
22 @implementation StudyRoom
23 {
24 
25 
26 }
27 -(void)closeRoom{
28     NSLog(@"See you tomorrow!");
29 
30 }
31 -(void)CloseRoomWorningWithPeople:(char *)people andWoring:(char *)Woring{
32 
33     NSLog(@"Hello,Mr.%s ,%s",people,Woring);
34 }
35 +(void)openDoorWithAdmin:(char *)admin{
36     NSLog(@"%s will open the door!",admin);
37 
38 }
39 @end
40 
41 int main(int argc, const char * argv[]) {
42     StudyRoom *S = [StudyRoom new];
43     NSLog(@"--------对象方法测试---------------");
44     [S closeRoom];
45     [S CloseRoomWorningWithPeople:"Jobs" andWoring:"You muet be go,now!"];
46     NSLog(@"--------类方法测试----------------");
47     [StudyRoom openDoorWithAdmin:"XinYueming"];
48     return 0;
49 }

 

posted @ 2017-02-21 11:07  BeanPaste  阅读(247)  评论(0编辑  收藏  举报