On different practice tests, I had been seeing answers on using boolean assignments in conditional statements which seemed inconsistent to me, so I tried the following:
public class testIt{
public static void main(String[] args){
boolean b = true;
if (b = false)
{ System.out.println("b is false");}
else
{System.out.println("b is true");}
System.out.println("after conditional, b is " + b);
boolean c = false;
if (c = true)
{System.out.println("c is true");}
else
{System.out.println("c is false");}
System.out.println("after conditional, c is " + c);
}
}
My results were:
b is true
after conditional, b is false
c is true
after conditional, c is true
How can this be? The assignment of the true to c, which was previously false, seems to have changed it right away, so that it is reset in time to go into the true block. However, the assignment of the false to b, which was previously true, seems to be delayed somehow so that it goes into the wrong block and then resets when it's too late!