Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


They had given one progam
final HashMap hm=new HashMap();
public void show()
{
hm.put("name",value);
}
in this prg here the final hashtable value can be changed in
put method,its the prg run?

Answers were Sorted based on User's Feedback



They had given one progam final HashMap hm=new HashMap(); public void show() { hm.put("name..

Answer / kr

hash map values can be modified but the hashmap object
cannot be modified
hm.put("name",value); //allowed

hm = new HashMap() // throw error since the object is fianl

Is This Answer Correct ?    19 Yes 1 No

They had given one progam final HashMap hm=new HashMap(); public void show() { hm.put("name..

Answer / abhinav mutreja

Thats Correct that contents of the HashMap can be changed
even if HashMap is declared as final.
If you contents also should not get changed then you can use

Map hm = Collections.unmodifiableMap(new HashMap());
here if you do
hm.put(1,"Hi");

then it would give Runtime Exception :-
Exception in thread "main"
java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableMap.put
(Unknown Source)

Is This Answer Correct ?    8 Yes 0 No

They had given one progam final HashMap hm=new HashMap(); public void show() { hm.put("name..

Answer / cool_duzz

no.. final cannot be modified..

Is This Answer Correct ?    2 Yes 9 No

Post New Answer

More Core Java Interview Questions

what is a thread?

13 Answers   IBM, SunGard,


Can we create our own wrapper class in java?

0 Answers  


Garbage collection in java?

0 Answers  


In a my eclipse editor if i want to switch from jdk 1.4 to jdk 1.6 how to do that???? Initially i have jdk1.4

1 Answers   Tech Mahindra,


Which data type is a class in java?

0 Answers  


What are exceptions

0 Answers   Futures First,


Why are there no global variables in java?

0 Answers  


What are blocks?.

1 Answers   TCS,


Keywords in Exceptions?

2 Answers  


Is there a case when finally will not execute?

0 Answers  


Can we execute java program without main method?

0 Answers  


Which package has light weight components in java programming?

0 Answers  


Categories