Green mock 3 第11题
What will happen when you attempt to compile and run the following code
class Base{
public void Base(){
System.out.println("Base");
}
}
public class In extends Base{
public static void main(String argv[]){
In i=new In();
}
}
1) Compile time error Base is a keyword
2) Compilation and no output at runtime
3) Output of Base
4) Runtime error Base has no valid constructor
ANSWER:
2) Compilation and no output at runtime
Because the method in Base called Base has a return type it is not a constructor and there for does not get called on creation of an instance of its child class In
我认为没有可选项,因为In和Base都未定义Constructor