先贴我的练习代码:
main.m
//
// main.m
// 4th
//
// Created by Morning on 2015/11/09.
// Copyright © 2015年 Morning. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Dog.h"
#import "Jiwawa.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
Dog * dog = [[Dog alloc] init];
//通过.来调用存取方法
dog.age=10;
dog.weight=12.3;
[dog bark];
//通过消息调用存取方法
[dog setAge:11];
[dog setWeight:32.1];
[dog bark];
Dog* jww = [Jiwawa new];
//子类通过.来调用存取方法
jww.age=2;
jww.weight=12;
[jww bark];
//子类通过消息调用存取方法
[jww setAge:4];
[jww setWeight:21];
[jww bark];
}
return 0;
}
Dog.h: