wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Objective 7.6 Java Operators (instanceof) Operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Objective 7.6 Java Operators (instanceof) Operator" Watch "Objective 7.6 Java Operators (instanceof) Operator" New topic
Author

Objective 7.6 Java Operators (instanceof) Operator

John Paterson
Ranch Hand

Joined: Mar 12, 2012
Posts: 121
Hi Friends,

I have some difficulty in understanding a particular row in Table 4.1 from Kathy Sierra SCJP 6 book. The table is in page 298.

In row 5, Foo[] is compared against Foo, Bar and Face with the instance of operator and the result is false. What I don't undserstand is in row 7, Foo[1] is compared against Foo, Bar, Face Object and this time the reslt is True??? I don't understand why. Hope somebody can help out. The code on which all this is based is as follow:




Thanks.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
John Paterson wrote:In row 5, Foo[] is compared against Foo, Bar and Face with the instance of operator and the result is false.

I don't have the book so I may be missing something. Anyways, I was not at all able to compare between Foo[] type against Foo. I received a compilation error. How do you got instanceof returning false?

Can you show the operator code?

Helen Ma
Ranch Hand

Joined: Nov 01, 2011
Posts: 451
John Paterson wrote:
In row 5, Foo[] is compared against Foo, Bar and Face with the instance of operator and the result is false. What I don't undserstand is in row 7, Foo[1] is compared against Foo, Bar, Face Object and this time the reslt is True??? I don't understand why. Hope somebody can help out. The code on which all this is based is as follow:






Foo[1] refers to an object of Foo type. For example Foo[1] = new Foo();
Is Foo[1] an instance of Foo? True
Is Foo[1] an instance of Bar? True
Is Foo[1] an instance of Face? True
Is Foo[1] an instance of Object? True

Foo[] is an array. It is an instance of Object, but it is not an instance of Foo, Bar or Face.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Objective 7.6 Java Operators (instanceof) Operator