1 interface IA 2 { 3 int Method(); 4 } 5 interface IB : IA 6 { 7 new double Method(); 8 } 9 class MyClass : IB10 {11 public double Method()12 {13 ...14 }15 16 int IA.Method()17 {18 ...19 }20 }我的問題是:在IB中我把IA的方法給隱藏了,為什么在MyClass中還要實現(xiàn)IA中的Method()。我試過了,如果不實現(xiàn),會產(chǎn)生編譯錯誤的。
2 回答

蕪湖不蕪
TA貢獻1796條經(jīng)驗 獲得超7個贊
MyClass在語法上是應(yīng)該可以轉(zhuǎn)換為IA接口的,轉(zhuǎn)換為IA接口的時候就可以調(diào)用IA的int Method()了,你不實現(xiàn)IA的方法,那就出錯了。

蝴蝶刀刀
TA貢獻1801條經(jīng)驗 獲得超8個贊
MyClass間接實現(xiàn)了IA,那么就會有這樣的代碼:
IA ia = new MyClass();
int n = ia.Method();
因此就必須要顯式實現(xiàn)IA中的方法。
MyClass myClass = new MyClass();
double d = myClass.Method();
而直接調(diào)用MyClass的Method方法,得到的是double類型。
- 2 回答
- 0 關(guān)注
- 565 瀏覽
添加回答
舉報
0/150
提交
取消