aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question from Exam Cram CD! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question from Exam Cram CD!" Watch "Question from Exam Cram CD!" New topic
Author

Question from Exam Cram CD!

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
int evtct =0;
AWTEvent lastE;
public void SaveEvent(AWTEvent evt)
{
lastE=evt;
evtct++;
}
Which of the following will make calls of SaveEvent would run without causing an exception
1)call with an AWTEvent objectreference
2) call with an ActionEvent object reference
3) call with an Event object reference
4) call with null value
Please I need explanation on this question as well answer.
Thanks in advacne.
Nirmal
Marcela Blei
Ranch Hand

Joined: Jun 28, 2000
Posts: 477
int evtct =0;
AWTEvent lastE;
public void SaveEvent(AWTEvent evt)
{
lastE=evt;
evtct++;
}
Which of the following will make calls of SaveEvent would run without causing an exception
1)call with an AWTEvent objectreference
2) call with an ActionEvent object reference
3) call with an Event object reference
4) call with null value
1) obviusly is right.
2) Is right because ActionEvent inherit from AWTEvent.
3) Is wrong because Event doesn�t belong to the same hierachy, it�s from the old event model (Java 1.0 event model).
4) Is right because you can initialize an object with a null value
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

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.
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.
Hope this helps..

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question from Exam Cram CD!
 
Similar Threads
Calling a method
from hardest questions
Exam Cram: page#112, Chapter #6, Question#3
Calling a method
Question, reference, package