Originally posted by dolly shah:
int i = 10;
int j = 10;
boolean b = false;
if( b = i == j)
System.out.println("True");
else
System.out.println("False");
Compilation error at line 4.
Runtime error exception at line 4.
Prints "True".-answer
Prints "False".
explanation
Conditional operators have higher precedence than assignment operator.
Here in if statement if( b = i == j), It should be if( b =( i == j)). If I am wrong please correct me.
Even if it goes that way what exactly you get inside the "if"? Remember "if" can have only results of type
boolean inside the parentheses.