Page 1 of 1
About Question com.enthuware.ets.scjp.v6.2.489 :
Posted: Wed Jan 02, 2013 10:31 pm
by yabmob
Why is "It will throw an AssertionException if 'i' is not equal to 20" not the correct answer ?
Re: About Question com.enthuware.ets.scjp.v6.2.489 :
Posted: Thu Jan 03, 2013 7:38 am
by admin
Because the correct name is AssertionError and not AssertionException.
HTH,
Paul.
Re: About Question com.enthuware.ets.scjp.v6.2.489 :
Posted: Fri Feb 01, 2013 12:26 pm
by Anu
HI, If I run this It should be throwing assertion error
But In this case it is printing 9 !!
Am I missing something here.? Please reply.
public class AssertTest {
public static void main(String[] args) {
m1();
}
static public void m1()
{
int i = 9;
try{
assert i == 20;
}
catch(Exception e){
i = 20; }
System.out.println(i);
}
}
}
Re: About Question com.enthuware.ets.scjp.v6.2.489 :
Posted: Fri Feb 01, 2013 12:36 pm
by Anu
Forgot to mention taht I have enabled Assertion while running it
Re: About Question com.enthuware.ets.scjp.v6.2.489 :
Posted: Fri Feb 01, 2013 12:50 pm
by Anu
Never mind...
I had put -ea in program arguments in eclipse.
It shd have been in VM arguments.
Question: About Question com.enthuware.ets.scjp.v6.2.489 :
Posted: Tue Jul 12, 2016 5:56 pm
by msalam4
Why "The program will not compile" is not the answer, since "i" is a local variable and it's not initialized?
Re: About Question com.enthuware.ets.scjp.v6.2.489 :
Posted: Tue Jul 12, 2016 11:00 pm
by admin
Why do you think it is not initialized when the code clearly says: //code that initializes i goes here