What will be the result of attempting to compile and run the following class?
public class Main{ public static void main (String args [] ){ int i, j, k; i = j = k = 9; System.out.println (i); } }
Select 2 options
Correct Options are : C E
Every expression has a value, in this case the value of the expression is the value that is assigned to the Right Hand Side of the equation.
k has a value of 9 which is assigned to j and then to i.
Another implication of this is :
boolean b = false; if ( b = true) { System.out.println ("TRUE"); }
The above code is valid and will print TRUE.
Because b = true has a boolean value, which is what an if statement expects.
if ( i = 5) { ... } is not valid because the value of the expression i = 5 is an int (5) and not a boolean.