This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes instanceof query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "instanceof query" Watch "instanceof query" New topic
Author

instanceof query

geet kaur
Ranch Hand

Joined: Sep 03, 2008
Posts: 78
guys
do we check the type of the refernce varaible against the type provided on the right side of the operator or we just compare the object it is refering to?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18138
    
  39

do we check the type of the refernce varaible against the type provided on the right side of the operator or we just compare the object it is refering to?


Obviously, it is checking the type of the actual object being referred to to a specific type. Checking the type of the reference variable is kinda silly -- as you can figure it out before you compile and replace the expression with a true or false.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: instanceof query
 
Similar Threads
instanceof
Reference Variable Casting?
instanceOf Confusion
Reg. casting from Khalid Mughal
Confused with instanceof, please help