zoukankan      html  css  js  c++  java
  • 类的属性,初始化函数,结束函数

    #import <Foundation/Foundation.h>

    //声明了一个类Init 

    @interface Init : NSObject

    {

        int a;

        int b;

        NSString *name;

    }

     

    @propertyint a,b;//设置函数的默认属性设置

    @end

     

    @implementation Init

     

    @synthesize a,b;

     

    -(id)init//默认的初始化函数

    {

        self=[super init];  //父类的初始化

        if (self) {

            a=19;

            b=89;

            name=[[NSStringalloc] initWithFormat:@"就像秋风带走我的思念,我的梦"];

            NSLog(@"这时初始化函数");

        }

        returnself;

    }

     

    -(void) dealloc//默认的结束函数

    {

        NSLog(@"这时最后输出的") ;

        [name release];

        [super dealloc];

    }

     

     

    @end

    int main(int argc, const char * argv[])

    {

     

        @autoreleasepool {

            Init *aa=[[Init alloc] init];  //声明指针

            [aa release];释放aa对象

            // insert code here...

            NSLog(@"Hello, World!");

        

        }

        return 0;

    }

    结果是:

  • 相关阅读:
    Git的初步学习
    Git的初步学习
    微信小程序我的界面
    微信小程序我的界面
    Day2:html和css
    Day2:html和css
    Day1:html和css
    Day1:html和css
    Java之JDK7的新语法探索
    Java之JDK7的新语法探索
  • 原文地址:https://www.cnblogs.com/flyingdreaming/p/classandinitanddealloc.html
Copyright © 2011-2022 走看看