About Question com.enthuware.ets.scjp.v6.2.489 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
yabmob
Posts: 5
Joined: Wed Nov 21, 2012 12:31 pm
Contact:

About Question com.enthuware.ets.scjp.v6.2.489 :

Post by yabmob »

Why is "It will throw an AssertionException if 'i' is not equal to 20" not the correct answer ?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.489 :

Post by admin »

Because the correct name is AssertionError and not AssertionException.

HTH,
Paul.

Anu

Re: About Question com.enthuware.ets.scjp.v6.2.489 :

Post 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);
}
}
}

Anu

Re: About Question com.enthuware.ets.scjp.v6.2.489 :

Post by Anu »

Forgot to mention taht I have enabled Assertion while running it

Anu

Re: About Question com.enthuware.ets.scjp.v6.2.489 :

Post by Anu »

Never mind...
I had put -ea in program arguments in eclipse.
It shd have been in VM arguments.

msalam4
Posts: 3
Joined: Sat Feb 27, 2016 1:55 pm
Contact:

Question: About Question com.enthuware.ets.scjp.v6.2.489 :

Post by msalam4 »

Why "The program will not compile" is not the answer, since "i" is a local variable and it's not initialized?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.489 :

Post by admin »

Why do you think it is not initialized when the code clearly says: //code that initializes i goes here

Post Reply

Who is online

Users browsing this forum: No registered users and 35 guests