How many numbers gets printed when the following JSTL code fragment is executed? Select the one correct answer.

  1. No number gets printed.

  2. One number gets printed.

  3. Two numbers gets printed.

  4. Three numbers gets printed.

  5. Four numbers gets printed.


Correct Option: B
Explanation:

To solve this question, the user needs to know the working of the JSTL choose tag and the conditions used in the when tags.

The code fragment defines a variable 'item' whose value is set to 2. The code then goes on to use the choose tag which is used for conditional processing. The choose tag contains multiple when tags. The when tags are evaluated in the order they are written, and the first condition that is true gets executed. If none of the conditions is true, the code in the otherwise tag is executed.

Looking at the code, the value of the 'item' variable is 2. The first condition in the when tags is "${item>0}" which is true for the given value of item. Therefore, the code inside the first when tag is executed which prints the number 1. The code doesn't go on to evaluate the other when tags because the first condition is true.

So, the answer is:

The Answer is: B. One number gets printed.

Find more quizzes: