all Exceptions other than those extending RuntimeExceptions are specified as Checked Exceptions . These when thrown from a inside method should be either caught or declared in the throws clause of the method.
So in the question, Exception, BaseException, SubException, are of checked Exceptions. Since none of them are caugfht inside method , they should be in the throws clause.
Again , if a method throws Exception , that will be enough for all the subTypes of Exception.
RuntimeException is supposed to bubble up since they are due to run time error and not due to run time errors . So it is not must to try catch or throw a RuntimeExceptions. But still they can
also be caught ..
see this code
public class Test3 {
public void aMethod(int i) throws Exception, RuntimeException{
if(i==0) throw new RuntimeException();
throw new Exception();
}
public static void main(
String args[]){
Test3 t3= new Test3();
for(int i = 0; i<2 ;i++){
try{
t3.aMethod(i);
}catch(RuntimeException e){
System.out.println("RuntimeException");
}
catch(Exception e){
System.out.println("Exception");
}
}
}
}
prints
Exception
RuntimeException
So in the question, D is the answer.