main.m
// 14-【掌握】有参方法的声明实现和调用
//
// Created by teacher on 15/12/7.
// Copyright © 2015年 sige. All rights reserved.
//
#import <Foundation/Foundation.h>
// 所有的类型 都要用 ()包裹
@interface Person : NSObject
{
@public
NSString * _name;
int _age;
}
// 对象方- 有参数的 : , 方法名字 是 eat: 参数有 1 个 NSString 类型 参数的名字 是 foodName
// 方法的返回值类型是 void
- (void)eat:(NSString *)foodName;
// 张三边吃边喝
// 方法名字 是 eat: :
- (void)eat:(NSString *)foodName :(NSString *)drinkName;
// 方法名 eatFood: andDrink:
- (void)eatFood:(NSString *)foodName andDrink:(NSString *)drinkName;
@end
@implementation Person
- (void)eat:(NSString *)foodName{
NSLog(@" %@ 在 吃 %@ ",_name, foodName);
}
- (void)eat:(NSString *)foodName :(NSString *)drinkName{
NSLog(@" %@ 在 吃 %@ 开心的和 %@ ",_name,foodName,drinkName);
}
- (void)eatFood:(NSString *)foodName andDrink:(NSString *)drinkName{
NSLog(@" %@ 在 吃 %@ 开心的和 %@ ",_name,foodName,drinkName);
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
Person * zhangsan = [Person new];
zhangsan->_name = @"张三丰";
[zhangsan eat:@"shi"];
[zhangsan eat:@"shi" :@"橙汁"];
[zhangsan eatFood:@"shi" andDrink:@"橙汁"];
}
return 0;
} |
|