• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
I'm full of tinier men! And a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic