Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exam Cram: page#112, Chapter #6, Question#3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exam Cram: page#112, Chapter #6, Question#3" Watch "Exam Cram: page#112, Chapter #6, Question#3" New topic
Author

Exam Cram: page#112, Chapter #6, Question#3

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Following is the question from Exam cram page 112 chapter #6

Consider the following Code
int evtCt=0;
AWTEvent lastE;
public void saveEvent(AWTEvent evt)
{
lastE = evt;
evtCT++;
}
Which of the follwoing calls of saveEvent would run without causing an exception.
a: an AWTEvent object refrence
b: an ActionEvent object refrence
c: an EventObiect object refrence
d: a null value
Answer is
a, b,d
If someone can explain this..
Sonali
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Originally posted by Sonali:
Following is the question from Exam cram page 112 chapter #6

Consider the following Code
int evtCt=0;
AWTEvent lastE;
public void saveEvent(AWTEvent evt)
{
lastE = evt;
evtCT++;
}
Which of the follwoing calls of saveEvent would run without causing an exception.
a: an AWTEvent object refrence
b: an ActionEvent object refrence
c: an EventObiect object refrence
d: a null value
Answer is
a, b,d
If someone can explain this..
Sonali

a - AwtEvent is the Object reference in the parameter list
b - is a subclass of AwtEvent so, it has everthing it needs (and more)
d - null is always a valid reference however you have to use caution on any operations which try to use it.
c - is incorrect because it is the super class to AwtEvent, super classes have some of the functionality of the subclass but, may and usually don't have all of them so, can't be used.

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
null is always a valid reference however you have to use caution on any operations which try to use it.
If someone can explain in a bit detail
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12759
    
    5
You can always assign the null special value to any reference variable or call to a method that expects a reference variable.
However, any attempt to use that reference is likely to result in a NullPointerException being thrown.
In the example of the question, no exception is thrown because the null value would just be stored in the lastE reference.
 
Consider Paul's rocket mass heater.
 
subject: Exam Cram: page#112, Chapter #6, Question#3
 
Similar Threads
Question, reference, package
Question from Exam Cram CD!
Calling a method
from hardest questions
Calling a method