wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes from hardest questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "from hardest questions" Watch "from hardest questions" New topic
Author

from hardest questions

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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.
Paul A
Ranch Hand

Joined: Aug 25, 2000
Posts: 44
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!


<A HREF="http://pages.about.com/jqplus" TARGET=_blank rel="nofollow">http://pages.about.com/jqplus</A> <BR>Get Certified, Guaranteed!
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hi, thanks very much for explaining this to me. That helps.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: from hardest questions