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/