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?
Answer Posted / 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 |
Post New Answer View All Answers
Which class is the superclass for every class in java programming?
What is re-factoring in software?
What is use of map in java?
How do you start a thread?
What are accessor methods in java?
What is the best way to findout the time/memory consuming process?
What is the difference between preemptive scheduling and time slicing?
Why can't we use static class instead of singleton?
Write a java program to check if a number is prime or not?
Is set sorted in java?
What does singleton class mean?
A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.
What is a instance variable in java?
What are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. Import java.net.* Versus import java.net.socket)?
What is a qms manual?