File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Understanding instanceof operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Understanding instanceof operator" Watch "Understanding instanceof operator" New topic
Author

Understanding instanceof operator

Ethan Bosco
Greenhorn

Joined: Nov 01, 2004
Posts: 15
From K & B book pg : 159 instanceof operator

Given

interface Face{}
class Bar implements Face{}
class Foo extends Bar{}

there is a table which says
----------------------------------------------------------------------
First Operandinstanceof OPerandResult
-----------------------------------------------------------------------
Foo[]Foo, Bar, Facefalse
Foo[]Objecttrue
Foo[1]Foo, Bar, Face, Objecttrue

can someone give me some line of code that will validate the above table?

Thanks in advance
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
You can use something similar to the code in this thread.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Ethan Bosco
Greenhorn

Joined: Nov 01, 2004
Posts: 15
Thanks Barry,
I am still unable to understand maybe I should format the table better

my Second attempt, My q esp how Foo[] instance of Foo equals false any code that I can try
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Ethan Bosco
Greenhorn

Joined: Nov 01, 2004
Posts: 15
Thanks for the code Barry , how about the third row in the table



Thanks again
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Now we are in the correct forum:

Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
My apologies, I did not see you were actually trying out the statement, I thought you just wanted me to write the next four lines for you.

The above code compiles and runs for me (java 1.5.0).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Understanding instanceof operator