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 Because the Base class has an integer constructor Java does not provide the "behind the scenes" zero parameter constructor.
No comments:
Post a Comment