早教吧 育儿知识 作业答案 考试题库 百科 知识分享

Java接口,继承QUESTION31Given:1.interfaceA{publicvoidaMethod();}2.interfaceB{publicvoidbMethod();}3.interfaceCextendsA,B{publicvoidcMethod();}4.classDimplementsB{5.publicvoidbMethod(){}6.}7.classEextendsDimp

题目详情
Java接口,继承
QUESTION 31
Given:
1. interface A { public void aMethod(); }
2. interface B { public void bMethod(); }
3. interface C extends A,B { public void cMethod(); }
4. class D implements B {
5. public void bMethod(){}
6. }
7. class E extends D implements C {
8. public void aMethod(){}
9. public void bMethod(){}
10. public void cMethod(){}
11. }
What is the result?
A. Compilation fails because of an error in line 3.
B. Compilation fails because of an error in line 7.
C. Compilation fails because of an error in line 9.
D. If you define D e = new E(), then e.bMethod() invokes the version of bMethod() defined in Line 5.
E. If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 5.
F. If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 9.
Answer: F
这里的强制类型转换十分不理解 还请高手详细解析一下这题
▼优质解答
答案和解析
E是D的子类所以E的实例可以声明为D类型变量e声明类型是D( D e ), 而实际类型是E( new E() ),不需要进行显示类型转换D e = (D)(new E()) 和 D e = new E()没有区别因为把变量e声明为D类型,D实现(implements)B,...