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 difference between type 4 driver and type 1 driver?

2 Answers   CMC, CTS, IBM, JK Technosoft, Napier Healthcare,


How do you sort objects in java?

0 Answers  


Explain reverse a linked list iterative solution in java?

0 Answers  


What are the 4 versions of java?

0 Answers  


What is the size of arraylist in java?

0 Answers  






What do you mean Abstraction in java?

0 Answers   Aspire, Infogain,


can two class in a code be public??if yes then how??

2 Answers  


What is the range of a character variable?

0 Answers  


How the elements are organized in BorderLayout?

5 Answers  


What are data structures in java?

0 Answers  


What is unicode full form?

0 Answers  


Why stringbuilder is not thread safe?

0 Answers  


Categories