Re: [問題] override superclass init時會call的fun
既然你sample code都寫出來了 實驗看看就知道啦
如果你在A的init中的[self xxx]丟一個breakpoint
然後創建一個b
就會發現即使你進到A的method裡 "self"永遠都還是B
既然B override了A的xxx method
[self xxx]自然就是call B的method囉
※ 引述《wfgh (lyle)》之銘言:
: 如果我override superclass的init裡會call的method
: 那[super init]時會call新的method還是原來的?
: ex:
: ClassA:NSObject
: - (id)init
: {
: self = [super init];
: [self xxx];
: return self;
: }
: - (void)xxx
: {
: do something
: }
: ClassB:ClassA
: - (id)init
: {
: self = [super init] //這裡會call A的xxx還是B的xxx呢?
: return self;
: }
: - (void)xxx
: {
: override......
: }_
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 199.2.242.199
推
11/29 19:55, , 1F
11/29 19:55, 1F
→
11/29 23:19, , 2F
11/29 23:19, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):