Rectangular 父类
Rectangle 子类
==============================
main.m
#import <Foundation/Foundation.h>
#import "Rectangle.h"
int main(int argc,const char * argv[]) {
@autoreleasepool {
//多态
Rectangular *ra=[Rectangularnew];
ra=[Rectangle new];
ra.width=10;
ra.height=2;
[ra area];
}
return 0;
}
===============================================================Rectangle.h
#import <Foundation/Foundation.h>
#import "Rectangular.h"
@interface Rectangle : Rectangular
-(void)area;
@end
==================================================================#import "Rectangle.h"
@implementation Rectangle
-(void)area
{
NSLog(@"%f",self.width*self.height/2);
}
@end
===============================================================Rectanguar.h
#import <Foundation/Foundation.h>
@interface Rectangular : NSObject
@property(nonatomic,assign)CGFloat width;
@property(nonatomic,assign)CGFloat height;
-(void)area;
@end
=====================================================Rectanguar.m
#import "Rectangular.h"
static Rectangular *re=nil;
@implementation Rectangular
@synthesize width;
@synthesize height;
-(void)area
{
NSLog(@"aa%.2f %.2f",self.width,self.height);
}
@end