I came across this question is marcus green's tutorial:
What will happen when you attempt to compile and run the following class?
class Base{
Base(int i){
System.out.println("Base");
}
}
class Severn extends Base{
public static void main(
String argv[]){
Severn s = new Severn();
}
void Severn(){
System.out.println("Severn");
}
}
1) Compilation and output of the string "Severn" at runtime
2) Compile time error
3) Compilation and no output at runtime
4) Compilation and output of the string "Base"
Answer = 2) Compile time error
An error occurs when the class Severn attempts to call the zero parameter constructor in the class Base
According to me, the correct answer should have been 3, since void makes the constructor Severn into a method with the same name as the class. So nothing is printed. It does not even call the Base class.
Some one please help.
Thank You,
Kamil.