Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

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

 
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.
 
Ranch Hand
Posts: 1249
Spring Java 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.
 
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.
 
Creativity is allowing yourself to make mistakes; art is knowing which ones to keep. Keep this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic