set,get方法练习
//1.创建一个人类,设置属性 人类名称,人类肤色,人类年龄
// 功能: 奔跑,学习,打游戏
//2.实例化两个人类小明,小红, 分别显示他们的功能和属性
// 3.小明问小红,你的肤色是什么,小红可以回答,我的肤色是XX
// People.h
// OC_FirstDay
//
// Created by whunf on 16/3/28.
// Copyright © 2016年 whuf. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface People : NSObject
{
NSString* name;
NSString* skin;
int age;
}
//设置属性的值
- (void)setName:(NSString *) newName;
- (void)setSkin:(NSString *) newSKin;
- (void)setAge:(int) newAge;
//获取属性的值
- (NSString *)name;
- (NSString *)skin;
- (int)age;
//奔跑
- (void)run;
//玩游戏
- (void)playGame;
//玩游戏
- (void)study;
//显示
- (void)display;
//获取其他类的数据
- (void)TellMeWithYourSkin:(People *) people;
@end
//
// People.m
// OC_FirstDay
//
// Created by whunf on 16/3/28.
// Copyright © 2016年 whuf. All rights reserved.
//
#import "People.h"
@implementation People
- (void)run
{
NSLog(@"奔跑");
}
- (void)playGame
{
NSLog(@"打游戏");
}
- (void)study
{
NSLog(@"学习");
}
#pragma mark 设置属性
- (void)setSkin:(NSString *)newSKin
{
skin = newSKin;
}
- (void)setName:(NSString *)newName
{
name = newName;
}
- (void)setAge:(int)newAge
{
age = newAge;
}
#pragma mark 获取属性
- (NSString *)name
{
return name;
}
- (NSString *)skin
{
return skin;
}
- (int)age
{
return age;
}
#pragma mark 获取其他类的信息
- (void)TellMeWithYourSkin:(People *) people
{
NSLog(@"%@:你的肤色是什么?",name);
NSLog(@"%@:我的肤色是%@",[people name],[people skin]);
}
#pragma mark 显示
- (void)display
{
NSLog(@"name:%@,skin:%@,age:%d",name,skin,age);
}
@end
#import <Foundation/Foundation.h>
#import "People.h"
int main(int argc, const char * argv[]) {
//1.创建一个人类,设置属性 人类名称,人类肤色,人类年龄
// 功能: 奔跑,学习,打游戏
//2.实例化两个人类小明,小红, 分别显示他们的功能和属性
// 3.小明问小红,你的肤色是什么,小红可以回答,我的肤色是XX
@autoreleasepool {
People *xiaoming = [[People alloc]init];
People *xiaohong = [[People alloc]init];
[xiaoming setName:@"小明"];
[xiaoming setSkin:@"黄色"];
[xiaoming setAge:18];
[xiaohong setName:@"小红"];
[xiaohong setSkin:@"红色"];
[xiaohong setAge:200];
[xiaohong run];
[xiaoming playGame];
[xiaohong display];
[xiaoming display];
[xiaoming TellMeWithYourSkin:xiaohong];
}
return 0;
}