Java OCA OCP Practice Question 1564

Question

The following code snippet will print 4.

public class Main {

   public static void main(String[] args) {
      int i1 = 1, i2 = 2, i3 = 3;
      int i4 = i1 + (i2 = i3);
      System.out.println(i4);
   }
}

Select 1 option

  • A. True
  • B. False


Correct Option is  : A

Note

First the value of i 1 is evaluated (i.e. 1).

Now, i2 is assigned the value of i3 i.e. i2 becomes 3.

Finally i4 gets 1 +3 i.e. 4.




PreviousNext

Related