This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A Question from Marcus exam 3 about instanceof Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A Question from Marcus exam 3 about instanceof" Watch "A Question from Marcus exam 3 about instanceof" New topic
Author

A Question from Marcus exam 3 about instanceof

Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Question 6).
Which of the following statements are true?
1) The instanceof operator can be used to determine if a reference is an instance of a class, but not an interface.
2) The instanceof operator can be used to determine if a reference is an instance of a particular primitive wrapper class
3) The instanceof operator will only determine if a reference is an instance of a class immediately above in the hierarchy but no further up the inheritance chain
4) The instanceof operator can be used to determine if one reference is of the same class as another reference thus

The answer is:
2) The instanceof operator can be used to determine if a reference is an instance of a particular primitive wrapper class

I thought 4 is also a true statement?
Brian Joseph
Ranch Hand

Joined: May 16, 2003
Posts: 160
Mm, I'm having trouble understanding number 4, and is it cut off?? Maybe all they're asking is if you can do this:

[ June 17, 2003: Message edited by: Brian Joseph ]
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Hi Brian,
No it is not cut off. That is how much was there.
Now i understand it. instanceof operators takes a reference and a class and tells if reference is of that class type. It does not take two references and checks if they both blong to same class.
Thanks
Barkat
[ June 17, 2003: Message edited by: Barkat Mardhani ]
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
4 is wrong because you can't use instanceof to compare one reference to another.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
Don't get me started about those stupid light bulbs.
 
subject: A Question from Marcus exam 3 about instanceof