1. public class Test2 extends MyBase implements MyInterface { int x = 0; 5. public Test2(int inVal) throws Exception { 7. if( inVal != this.x) { 9. throw new Exception("Invalid input"); } } public static void main(String[] args) { 15. Test2 t = new Test2(4); } }
A.the code fails to compile at line1. it's not valid to both implement an interface and extends from a parent class simultaneously.
B.the code fails to compile at line 5.int's not valid for constructors to throw exceptions.
C.the code fails to compile at line9,because this is not valid way to throw an exception.
D.the code fails to compile at line15.the compiler complains that there is an uncaught exception.
E.the code fails to compile at line7,because this is not a valid way to reference variable x.
答案是D,可是我选了A,大家帮帮忙看一下,如果选D帮忙解释一下,谢谢了