I took
SCJP on saturday. I posted this question on certfication results forum, but nobody seems to answer it there, so I am posting it here.
the questions were all ok, except one that i could not think an answer for.
I don't remember it completely, but there was a statement between the try and catch, and should be giving a compiler error. However, the question was a short answer one and value of a
string variable was asked. it looked somethng like this:
public class Class
{
String counter = "";
void foo(int i){
try
{
if(i==0)
throw new Exception();
}
counter += "1";
catch
{
//some code
}
finally
{
//some code
}
}
public static void main(String [] args)
{
foo(1);
foo(0); //*****
}
}
what is the value of variable counter at //*****
according to me, the code should not compile since there is a statement between the try/catch.
any comments? if it really can't compile, how should i go forward telling SUN this thing? they should not be penalizing me for this question in that case.