object-c中类的继承

子类继承父类

@interface 子类:父类{}

@end

子类具有父类的全部成员变量和全部方法。


#import <Foundation/Foundation.h>

@interface Fruit:NSObject

@property (nonatomic,assign) double weight;

-(void) info;

@end


#import "Fruit.h"

@implemetation Fruit

-(void) info{}

@end


#import <Foundation/Foundation.h>

#import "Fruit.h"

@interface Apple:Fruit

@end


#import "Apple.h"

int main(int arg,char*argi[]){

@autoreleasepool{

Apple* a=[[Apple alloc] init];

a.weight=50;

[a info];


}

}


super关键字

用以在子类方法中调用父类被覆盖的方法

你可能感兴趣的:(object-c中类的继承)