| Author |
HFSJ Mock Exam Question 55
|
julius hock
Greenhorn
Joined: Apr 06, 2006
Posts: 7
|
|
I'm wondering what is the different between setAttribute("key", new X()); //print "B" setAttribute("key", "x") // print "UB"; Question 55. 15. req.getSession().setAttribute("key", new X()); 16. req.getSession().setAttribute("key", new X()); 17. req.getSession().setAttribute("key", "x"); 18. req.getSession().removeAttribute("key"); public void valueBound(HttpSessionBindingEvent event){ System.out.println("B"); } public void valueUnbound(HttpSessionBindingEvent event){ System.out.println("UB"); } Answer: B. BBUBUB Any help would be much appreciated.
|
 |
Adam Czysciak
Ranch Hand
Joined: Feb 25, 2005
Posts: 82
|
|
I'm wondering what is the different between setAttribute("key", new X()); //print "B" setAttribute("key", "x") // print "UB"; Question 55. 15. req.getSession().setAttribute("key", new X()); 16. req.getSession().setAttribute("key", new X()); 17. req.getSession().setAttribute("key", "x"); 18. req.getSession().removeAttribute("key"); } Answer: B. BBUBUB
The B/UB are printed only for elements of class X. "x" is a String... So: 15. new X() is created, prints "B" 16. another X() object is created and bound to session, so "B" is printed. But previous object created in line 15 is removed, so "UB" is printed too. 17. it removes object put in line 16 (so prints "UB") and inserts String object, so nothing more is printed. So, it prints BBUBUB. BTW: Personally for me it would be more logical that it prints BUBBUB (eg line 16 should first unbound previous object and then bound new object). But BBUBUB was the only answer that could fit for me while answering this question. And no - I didn't check it
|
Adam<br /> <br /><i>SCJA, SCJP 5.0, SCWCD 1.4, SCBCD 5, SCEA 5</i>
|
 |
 |
|
|
subject: HFSJ Mock Exam Question 55
|
|
|