This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Map map = new Hashmap() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Map map = new Hashmap()" Watch "Map map = new Hashmap()" New topic
Author

Map map = new Hashmap()

yamini nadella
Ranch Hand

Joined: Apr 13, 2004
Posts: 257
Assume Map interface has 10 public methods. Hashmap class implemented Map interface and some extra methods, total 20 public methods.
Map map = new Hashmap()
From this map object how many methods can I access. Can I access 10 or 20?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
You can only access the 10 methods of Map through the reference map.
You would, in your example, have to cast the reference map to a HashMap reference if you wanted to access all of HashMap's methods.
For instance: ((HashMap)map).someMethodSpecificToHashMap()


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
wood burning stoves
 
subject: Map map = new Hashmap()
 
Similar Threads
Hashtable or HashMap
When to use Hashmap (synchronized as needed) and when to use Concurrent hashmap?
HashMap's Map.Entry interface
Map vs. HashMap for hashes
Hashmap in java