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中還要實現IA中的Method()。我試過了,如果不實現,會產生編譯錯誤的。
2 回答

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