my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes instanceof operand Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "instanceof operand" Watch "instanceof operand" New topic
Author

instanceof operand

Ashwin Kumar
Ranch Hand

Joined: Apr 07, 2005
Posts: 78
Please clarify the following

Operands and Results Using instanceof Operator

First operand instanceof operand Result

1) Foo[] Foo,Bar,Face false

2) Foo[1] Foo,Bar,Face,Object true

Can anyone explain why the second one returns true when tested for instanceof operands given ??


Preparing SCEA..<br />SCBCD 5.0<br />SCWCD 1.4<br />SCJP 1.4
Ashwin Kumar
Ranch Hand

Joined: Apr 07, 2005
Posts: 78
Please ignore the above question here is modified message ..

Please clarify the following




Operands and Results Using instanceof Operator

1)

First operand - Foo[]

instanceof operand - Foo,Bar,Face

Result - false


2)

First operand - Foo[1]

instanceof operand - Foo,Bar,Face

Result - true


Can anyone explain why the second one returns true when tested for instanceof operands given ??
Animesh Shrivastava
Ranch Hand

Joined: Jul 19, 2004
Posts: 298
Foo[] can contain objects of Foo or its subclasses
When u do Foo[1] , u have in it contained either a Foo object or any of its subclass.

U can also have this done:
Face fc = Foo[1];// Because Face is a super interface of the Foo object
Bar br = Foo[1]; // Bar is Foo's super class, so thats ok

So thats the reason for ur second output.

1) Now for the first question keep in mind this:
Foo[] extends (Object, Object[]) and not Foo, Bar or Face

I hope this is ok
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: instanceof operand