On Marcus Green's Mock Exam #3 Question 11 is as follows:
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
// End of Sample Code
I chose 3 because I was under the impression that even though the subclass "In" has no constructor the JVM would automatically make one.
My first question is will the JVM make a default contructor?
Second,
I was also under the impression that when an object of a derived class is instantiated, the superclass constructor is called first. In this case the constructor for class "Base" would be called thereby printing out the string Base.
Is this not correct also?
Thanks in advance,
B Barnett