What will be the output when you compile and execute the following program.
Exception is the base class for all the Exception classes.
////////////////////////////////////////////
import java.io.*;
class Base
{
void
test() throws IOException {
System.out.println("Base.test()");
String a = null;
//Complex logic goes here
if(a == null)
throw new IOException("");
}
}
////////////////////////////////////////////
public class Child extends Base {
protected void test() throws Exception {
System.out.println("Child.test()");
Base.test(); //Call the parent method
throw new Exception("");
}
static public void main(String[] a) {
try {
new Child().test();
}
catch(Exception e) { }
}
}
Select most appropriate answer.
a) Child.test()
Base.test()
b) Compilation Error: The method void test() declared in class Child cannot override the method of the same signature declared in class Base. Their throws clauses are incompatible.
c) Compilation Error: The method void test() declared in class Child cannot override the method of the same signature declared in class Base.The access modifier is made more restrictive.
d) Runtime error. Cannot make the access modifier more restrictive for test()
<BOLD>
I think the answer should be b) but the given answer was c).
</BOLD>
When i tried to compile the above program i got the compilation error as in b).
Any comments???