Multiple choice technology programming languages

What gets printed when the following JSTL code fragment is executed? Select the one correct answer. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

  1. The JSTL code does not compile as an attribute for forEach tag is not correct.

  2. 0

  3. 2

  4. ABC

  5. Nothing gets printed as c.out statement does not get executed.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The forEach loop with begin=0, end=0, step=2 executes once with index=0. The var='item' sets the loop variable to 0. outputs 0. The key is that begin=0 end=0 means 'iterate from index 0 to index 0' in JSTL.

AI explanation

'0' is correct. has no `items` collection, so JSTL generates an integer sequence from `begin` to `end` (inclusive) stepping by `step` — here that's just the single value 0. Inside the loop, the loop's `var="item"` shadows the outer, so ${item} refers to the current loop index (0), not the earlier-set value of 2. The default="abc" on `` only kicks in if the value expression evaluates to null, which it doesn't here, so 'ABC' is wrong. The tag is syntactically valid JSTL, so 'doesn't compile' and 'nothing prints' are both wrong.