What is the output of the following program code?
public class Test{
public static void main(String args[]){
try{
int i;
return;
}
catch(Exception e){
System.out.print("inCatchBlock");
}
finally{
System.out.println("inFinallyBlock");
}
}
}
public class Test{
public static void main(String args[]){
try{
int i;
return;
}
catch(Exception e){
System.out.print("inCatchBlock");
}
finally{
System.out.println("inFinallyBlock");
}
}
}
A. inCatchBlock
B. inCatchBlock inFinallyBlock
C. inFinallyBlock
D. The program will return without printing anything
Answer: Option C
Here, no exception is occurring which we have to handle, that's why catch block isn't executing but we all know, whether an exception is caught or not, finally always executes, so all the statements inside of finally block occurs