• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Maps

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Out-put is false,true,true

And the explanation for the answer is
LinkedHashMap does not implement the Collection interface. LinkedHashMap extends HashMap and implements Map, Cloneable and Serializable.

But as per my knowledge LinkedHashMap does not extend HashMap

Please correct me if i'm wrong..

Thank u!
GMP
 
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No Ganesh,

LinkedHashMap is not a Collection, it extends HashMap, so the answer is correct.

Similaryly LinkedHashSet extends HashSet.
 
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the exam, only List and Set extends from Collection interface. Map interface and its implementer classes does not extends from Collection. It's a collection apart.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't forget that Queue also extends Collection, and that is on the exam as well
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Out-put is false,true,true

And the explanation for the answer is
LinkedHashMap does not implement the Collection interface. LinkedHashMap extends HashMap and implements Map, Cloneable and Serializable.

But as per my knowledge LinkedHashMap does not extend HashMap

Please correct me if i'm wrong..

Thank u!
GMP[/qb]<hr></blockquote>

Hi Ganesh:
The output is absolutely correct. Here,
(i) m instanceof Collection --> Now since m is a type of Map and Maps do not implement Collection interface.Hence, m is not an instanceof Collection.
So, It's FALSE

(ii) m instanceof Map----> As I said earlier m is a type of Map hence m is a instanceof Map. It's TRUE

(iii) m instanceof HashMap---> Here since the runtime type of m is LinkedHashMap,So m is basically a type of LinkedHashMap which extends HashMap. Hence, m is an instanceof HashMap.It's TRUE.

Hence, the output " false,true,true"



Regards
Swapnil
[ July 11, 2006: Message edited by: Swapnil Trivedi ]
 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But as per my knowledge LinkedHashMap does not extend HashMap



You may be feelig this way because of an errata in the K&B book. you can find the errata here https://coderanch.com/t/253802/java-programmer-SCJP/certification/Updated-Errata
or just simply strike off LinkedHashMap as an implementor of the Map interface and make it an implementor of HashMap.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But as per my knowledge LinkedHashMap does not extend HashMap



Then you better take a look at the Java 5.0 API.


[ July 12, 2006: Message edited by: Barry Gaunt ]
 
I am a man of mystery. Mostly because of this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic