• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

instanceof ?

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
interface Face { }
class Bar impliments Face { }
class Foo extends Bar { }


1. Foo[] instanceof FOO,Bar,Face

Ans. False

2. Foo[1] instanceof FOO, Bar , Face , Object

Ans True

why ???

this is given in Kathy sierra /Bert Bates book
table3.2 page 159

please help me why Foo[1] instanceof FOO, Bar , Face , Object
returns true
while
Foo[] instanceof FOO,Bar,Face
returns false
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this question could only be answered by someone who has a copy of the book in question, because the post above is too unclear to answer. Can anyone tell us what the question really says?
 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be they means, Foo[] as array object instead of a single array element. So Array object on its own it not related to Foo, Bar or Face.
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Foo[] instanceof FOO,Bar,Face

ans ] the answer is false because, FOO is a class , but FOO[] is a array of class FOO , because of which FOO is a array reference variable ( which is not a instance of class FOO )

2. Foo[1] instanceof FOO, Bar , Face , Object

ans] here FOO[1] is an element of the array FOO which means its a object of class FOO , as a result of which the result is true

somebody confirm the above stmts and reply in case of errors
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
since Foo is subclass of Bar => Foo[] is subclass of Bar[]
 
reply
    Bookmark Topic Watch Topic
  • New Topic