File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling a method

 
Gaia Nathan
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I came across this question and it has me puzzled. Can someone help me out? Here goes:
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.
End of question.
The answer given is a,b and d.
I can understand why a and b are chosen, but I don't understand why d is also chosen. Surely the method saveEvent() expects a parameter of some sort...
Thanks.

Thanks.
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This post seems to have nothing to do with the Cattle Drive assignments. I'm moving it to Java in General (beginning)
 
Colin Kenworthy
Ranch Hand
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaia,
All objects can have a null value, it is perfectly legitimate.
e.g. When you declare String myString; as a member variable it is given a null value by the compiler (and not the value "").
Objects with null values can be assigned to an object reference (e.g. through a method parameter, a return type, or String newString = myString .
It is only when we try and run a method or access a variable on the null object that we get an Exception raised.
 
Gaia Nathan
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Colin...I get it now..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic