Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
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
Paul Clapham
Ron McLeod
Jeanne Boyarsky
Tim Cooke
Sheriffs:
Liutauras Vilda
paul wheaton
Henry Wong
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Carey Brown
Frits Walraven
Bartenders:
Piet Souris
Himai Minh
Forum:
Programmer Certification (OCPJP)
LinkedHashMap and HashMap
Sricharan Modali
Greenhorn
Posts: 19
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Iam confused by the output of the following program.
import java.util.*; class GFC111 { public static void main (String[] args) { Object m = new LinkedHashMap(); System.out.print((m instanceof Collection)+","); System.out.print((m instanceof Map)+","); System.out.print(m instanceof HashMap); }}
the output is false, true, true
How can an this m
instanceof HashMap
be true? They are the same level isnt it?
Richard Quist
Ranch Hand
Posts: 96
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
LinkedHashMap
extends
HashMap, therefore LinkedHashMap
IS-A
HashMap and instanceof returns true.
Here's
the
java
api
doc
page for the class.
Hope that helps.
Rich
SCJP 1.4
Vineela Devi
Ranch Hand
Posts: 191
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Sricharan,
HashMap is the superclass of LinkedHashMap
and so, the code
m instanceof HashMap results in true.
Regards
Vineela
bacon. tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Dan's Question
Map Question
Collecion question
Maps
Objects and Collections
More...