Hi all
This is the question of Jtest mocktest (question no 54).
The answer of this question given is B,C,D.
But according to me correct answer should be A,C,D.
I am opposing B because, if you define 'finally' between 'try' and 'catch', the compiler will give error(like in the code given at the bottom.
So for me the sequence of try,catch,finally matters.
Can anybody make this more clear?
Which of the following statements about try,
catch, and finally are true?
A. A try block must always be followed by a catch
block
B. A try block can be followed either by a catch block
or a finally block, or both
C. A catch block must always be associated with a try
block
D. A finally can never stand on its own (that is, without
being associated with try block)
E. None of these are true
My code:
class javaprog
{
public static void main(
String [] a) {
go();
}
static void go(){
try{
throw new Exception();
}
finally{}
catch(Exception e){}
}
}