方法重载要保证三个条件

1在同一个类中

2.方法参数类型相同 名称相同

3.方法的参数不同

 

请看下面的例子

 

 

@interface whgMyObject : NSObject

-(void)print;

-(void)print:(int)a;

-(void)print:(int)a and:(int)b;

 

@end

@implementation whgMyObject

-(void)print

{

    NSLog(@"看着月亮一起笑");

}

-(void)print:(int)a

{

    NSLog(@"老的不行不行还拥抱");

}

-(void)print:(int)a and:(int)b

{

    NSLog(@"甜甜见到你");

}

@end

 

如果代码我们在接口文件中再写个函数

-(int)print;编译器就会给我们报错的 

 

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2021-05-31
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-27
  • 2022-02-14
  • 2021-11-26
  • 2021-06-21
  • 2022-01-10
  • 2021-06-09
  • 2022-12-23
相关资源
相似解决方案