Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on Pno-:286(K&B) Book(instanceof)

 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
on page no 286 table no-4-1 column 6
book says if "Foo[] array is instanceof Foo,Bar,Face then result is false".
Now see code below i tried to convert above statement in code

Now code gives compile error.
By doubt is how Foo[] array can take Bar and Face Object.
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by gowher amin naik:
on page no 286 table no-4-1 column 6
book says if "Foo[] array is instanceof Foo,Bar,Face then result is false".
Now see code below i tried to convert above statement in code

Now code gives compile error.
By doubt is how Foo[] array can take Bar and Face Object.


Well I must say that code has so many errors.

1. Foo is a sub class for Bar and Face.
You cann't create an Reference of sub class which is pointing an object of Super class.

2. You are creating new Face() i.e. you are creating object of an Interface
An interface never be instantiated...

You can try below given code this will clear your situation.

[B][/B]

Hope this helps you.
 
Ramamoorthy Periasamy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
book says if "Foo[] array is instanceof Foo,Bar,Face then result is false".


Yes, ofcourse Foo[] is NOT an instanceof Foo, Bar, Face because Foo[] itself is an Object. Only Foo[] instanceof Object returns true.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic