This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt on Pno-:286(K&B) Book(instanceof) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt on Pno-:286(K&B) Book(instanceof)" Watch "Doubt on Pno-:286(K&B) Book(instanceof)" New topic
Author

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

Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643
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

Joined: Dec 27, 2005
Posts: 1249

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.


The Best way to predict your future is to create it - Every great individual common man
Ramamoorthy Periasamy
Ranch Hand

Joined: Feb 06, 2006
Posts: 30
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt on Pno-:286(K&B) Book(instanceof)
 
Similar Threads
Doubt: K&B 1.5 p. 286; table 4-1 (´┐Ż instanceof´┐Ż)
problem in "instanceof" operator and "searching(regex)"
instanceof doubt
doubt in instanceof operator..
instanceof