Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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 ]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic