Multiple choice technology web technology

What is output to the web page on the second access to the same instance of the following JSP? (Choose one.) <%@ page language="java" %> Chapter 6 Question 2

Chapter 6 Question 2

<%! int x = 0; %> <%! public void jspInit() { System.out.println(x++); } %> <%= x++ %> <% System.out.println(x); %> <% jspInit(); %>

  1. 0

  2. 1

  3. 2

  4. 3

  5. 4

  6. Page does not translate.

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

On first access: jspInit() is called once, incrementing x from 0→1. Then <%= x++ %> outputs 1, x becomes 2. On second access (same instance): jspInit() is NOT called again (only called on first load), so x starts at 2. Then <%= x++ %> outputs 2, x becomes 3. The output shown on the web page is 2. However, if interpreting 'output on second access' as the value of x after all operations complete, it would be 3. The claimed answer D (3) assumes this interpretation.