This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

from hardest questions  RSS feed

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, this one is from the bill hardest questions.
java.lang.Object
java.util.EventObject
java.awt.AWTEvent
java.awt.event.ActionEvent
suppose we have the following code to count events and save the most recent event
int evtCt = 0;
AWTEvent lastE;
public void saveEvent(AWTEvent evt){
lastE = evt;
evtCt++;
}
which of the following calls of saveEvent would run without causing an exception. Select all which are correct;
a call with an AWTEvent object reference;
b call with an ActionEvent object reference;
c call with an EventObject object reference;
d call with null value;
correct answer is a, b, d.

I can understand why a, b right. How about d, could explain me how the "null" worked here.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What, in the code, suggests you that it should not work?
In the method, the passed parameter is not accessed anywhere. So there is no chance of a NPE. All it is doing is incrementing the counter and assigning the passed value to lastE. So when you pass null, lastE is assigned null. But it is ok as it is not accessed anywhere.
HTH,
Paul
------------------
http://pages.about.com/jqplus
Get Certified, Guaranteed!
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, thanks very much for explaining this to me. That helps.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!