Objective-C编程语言课程笔记(七)多态(极客班)

一、运行时多态

Objective-C编程语言课程笔记(七)多态(极客班)_第1张图片
Paste_Image.png

1、重写

@implementation Rectangle
-(id)init{
  self=[super init];
  if(self){
    _length=10;
    _width=20;
  }
  return self;
}

-(void)draw{
  NSLog(@"Rectangle object draw:length=%d,width=%d",self.length,self.width);
}

-(void)print{
  NSLog(@"Rectangle Instance veriable %d",_data);
}

+(process){
  NSLog(@"Rectangle class process");
}

-(void)dealloc{
  NSLog(@"Rectangle dealloc");
}

-(int)no{
  NSLog(@"Rectangle no get");
  return super.no;
}

  -(void)setNo:(int)no{
  NSLog(@"Rectangle no set");
  super.no=no;
}

2、使用

Rectangle *rect=[[Rectangle alloc]init];
rect.no=200;
rect->_data++;
[rect draw];
[rect print];
[Rectangle process];
[rect move];

二、内存模型

Objective-C编程语言课程笔记(七)多态(极客班)_第2张图片
Paste_Image.png

·继承中的init和dealloc

Objective-C编程语言课程笔记(七)多态(极客班)_第3张图片
Paste_Image.png

你可能感兴趣的:(Objective-C编程语言课程笔记(七)多态(极客班))