• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Charles Lyon's book mock exam question 3 in chp 16

 
Himai Minh
Ranch Hand
Posts: 1360
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

3. <%request.setAttribute("list", null) ; %>
<jsp:useBean id="list" class="java.util.List" type="java.util.ArrayList" scope="request"/>

A. The list scripting variable is set to the value of the request-scoped attribute called list.
B. A new List object is created and assigned to both the list scripting variable and the list page-scoped attribute.
C. A new List object is created and assigned to both the list scripting variable and the list request-scoped attribute.
D. A runtime exception is thrown.
E. A translation error occurs.

(Choose two)

Answer: D, E
Explanation: ArrayList implements List, which cannot be instantiated (as it is an interface) and cannot be cast to a subclass type like ArrayList. The specification leaves the actual behavior undefined- such errors could result in either runtime exceptions (such as ClassCastException, InstantiationException or ClassNotFoundException) or translation errors. Regardless , certainly none of A to C will be correct.


I think the answer is only E.
When I tried it , it throws me this error :
org.apache.jasper.JasperException: /test.jsp (line: 14, column: 1) The value for the useBean class attribute java.util.List is invalid.


I never get any runtime exception.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2533
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never get any runtime exception.

The answer lies in the answer given by the book:
The specification leaves the actual behavior undefined
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic