What gets printed when the following program is compiled and run? class test { public static void main(String args[]) { int i,j,k,l=0; k = l++; j = ++k; i = j++; System.out.println(i); } }

  1. 1

  2. 3

  3. 2

  4. 0


Correct Option: A

AI Explanation

To determine the output of the program, let's go through the code step by step:

  1. Initialize the variables i, j, k, and l to 0.
  2. Assign the value of l to k and then increment the value of l by 1. So, k becomes 0 and l becomes 1.
  3. Increment the value of k by 1 and assign the result to j. So, j becomes 1 and k becomes 1.
  4. Assign the value of j to i and then increment the value of j by 1. So, i becomes 1 and j becomes 2.
  5. Print the value of i which is 1.

Therefore, the output of the program will be 1.

Hence, the correct answer is option A.

Find more quizzes: