What gets printed when the following program is compiled and run. Select the one correct answer. 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. 0

  2. 1

  3. 2

  4. 3


Correct Option: B

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) 0 - This option is incorrect because the value of "i" is incremented after being assigned to "j" in the statement "i = j++". Therefore, the value of "i" will be 1, not 0.

Option B) 1 - This option is correct because the value of "i" is incremented after being assigned to "j" in the statement "i = j++". Therefore, the value of "i" will be 1.

Option C) 2 - This option is incorrect because the value of "i" is incremented after being assigned to "j" in the statement "i = j++". Therefore, the value of "i" will be 1, not 2.

Option D) 3 - This option is incorrect because the value of "i" is incremented after being assigned to "j" in the statement "i = j++". Therefore, the value of "i" will be 1, not 3.

The correct answer is B) 1. This option is correct because the value of "i" is incremented after being assigned to "j" in the statement "i = j++". Therefore, the value of "i" will be 1.

Find more quizzes: