About Question com.enthuware.ets.scjp.v6.2.286 :
Posted: Sun Aug 05, 2012 1:50 pm
Respected Sir,
The following question is:
What will the following code print?
int i = 0;
int j = 1;
if( (i++ == 0) && (j++ == 2) )
{
i = 12;
}
System.out.println(i+" "+j);
The answer given is it will print 1 2 ( i=1 and j=2)...
The explanation given says if( (i++ == 0) & (j++ == 2) ) is evaluated...
and rightfully gives 1 2 as answer..But the question as && operator which is a short circuit operator..
So only (i++ == 0) gets evaluated to true and the answer becomes 12 1..which is in option 4..
Please kindly correct this..
Thanks for the excellent Software,
Bharath K
Mysore,India
The following question is:
What will the following code print?
int i = 0;
int j = 1;
if( (i++ == 0) && (j++ == 2) )
{
i = 12;
}
System.out.println(i+" "+j);
The answer given is it will print 1 2 ( i=1 and j=2)...
The explanation given says if( (i++ == 0) & (j++ == 2) ) is evaluated...
and rightfully gives 1 2 as answer..But the question as && operator which is a short circuit operator..
So only (i++ == 0) gets evaluated to true and the answer becomes 12 1..which is in option 4..
Please kindly correct this..
Thanks for the excellent Software,
Bharath K
Mysore,India