1:创建一个car对象

 

头文件: 

     @interface car : NSObject {


          }
       @end

 实现文件:

@implementation car
-(id) init
{
    if (self = [super init]) {
NSLog(@"this is my name!and what's your name!");
}
return(self);
}//init
@end

 实践得出的结果:

     1若使用new创建的对象,则会自动调用方法init,代码如下:

        car *newCar = [car new];

     2如果使用alloc创建对象时,则需要手动调用方法:init。 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-30
  • 2021-04-14
  • 2021-10-19
  • 2022-02-07
  • 2022-01-02
  • 2021-12-05
猜你喜欢
  • 2022-01-30
  • 2022-12-23
  • 2021-08-14
  • 2021-09-12
  • 2021-11-06
  • 2022-01-24
  • 2021-06-17
相关资源
相似解决方案