OC 类 的声明


       

           Student.h

// @interface代表声明一个类
// : 代表继承
@interface Student : NSObject { // 成员变量要定义在下面的大括号中{}
    int age;
    int no;
}

// 在这里声明的所有方法都是公共

// age的get方法
// - 代表动态方法  + 代表静态方法
- (int)age;

// age的set方法
- (void)setAge:(int)newAge;

// no的get方法
- (int)no;

- (void)setAge:(int)newAge andNo:(int)newNo;
@end
#import "Student.h"

@implementation Student

- (int)age {
    NSLog(@"调用了getAge方法");
    return age;
}

- (void)setAge:(int)newAge {
    age = newAge;
    
    NSLog(@"调用了setAge方法");
}

- (int)no {
    return no;
}

- (void)setAge:(int)newAge andNo:(int)newNo {
    age = newAge;
    no = newNo;
}
@end

 

posted on 2017-05-24 16:37  守望星空  阅读(169)  评论(0编辑  收藏  举报

导航