wood burning stoves 2.0*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
 
Similar Threads
K&B book page 286 table 4-1: Is the array instnaceof result correct?
instanceof doubt
Using instanceof operator
instanceof
instanceof operand