Programming with Objective-C --- Working with objects


1, Objective-C的对象应该是一个类似C++的对象指针。不过这个指针是有引用计数自动释放的。
2, 函数调用, [someobject call_function], call_function is the member function of the class. some object is the instance of class.
3,  function override. when the function is also defined in the derived class. The function will override the base class.
4,  how to initialize the instance of class? [[ClassName alloc]init]; All class is inherit from NSObject. So all class has two member function(alloc, init);
5,  所有对象都是动态创建的。局部变量也是在stack中,当出作用域后,不可用。


#ifndef HelloWorld_FirstObjectiveCClass_h

#define HelloWorld_FirstObjectiveCClass_h


@interface CFirstClass : NSObject


@property NSString *firstname;

@property NSString *lastname;

@property NSDate   *birthdate;


- (void) sayhello;


- (void) say1:(NSString *)greeting;


+ (id)CFirstClass;


@end



@interface CSecondClass : CFirstClass


- (void) say1:(NSString *)greeting;


@end


#endif


#import

#import "FirstObjectiveCClass.h"


@implementation CFirstClass


+ (id)CFirstClass

{

    return   [[self alloc] init];

}

- (void)sayhello

{

    NSLog(@"hello");

    [self say1:@"gretting"];

}


- (void) say1:(NSString *)greeting

{

    NSLog(@"Firstclass %@",greeting);

}


@end



@implementation CSecondClass


- (void) say1:(NSString *)greeting

{

    NSLog(@"secondclass %@",greeting);

}


@end


#import

#import "AppDelegate.h"

#import "FirstObjectiveCClass.h"

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

    @autoreleasepool {

        CFirstClass * first;

        CSecondClass *second;

        if (first == nil) {

            first = [[CFirstClass alloc] init];

            [first sayhello];

            second = [[CSecondClass alloc] init];

            [second sayhello];

        }

        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

    }

}




来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30061551/viewspace-1689707/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/30061551/viewspace-1689707/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值