Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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

 
Ranch Foreman
Posts: 1897
12
  • 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.
 
Creator of Enthuware JWS+ V6
Posts: 3341
303
Android Eclipse IDE Chrome
  • 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

 
Don't MAKE me come back there with this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic