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
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 |
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 |
If all the methods in abstract class are declared as abstract then what is difference between abstract class and in interface?
Is java hashset ordered?
How many characters is 16 bytes?
What is the basic functionality of DataOutput interface in java?
which methods consisting of the serilizable interface?
what are the different non-access specifiers in java?
what is generics in jdk1.5?
What is string pool?
what is server side caching?
We can write any Java Logics in our JSP. Then why we are using servlets(Controller Layer) to interact with the DAO ?
What is the applet security manager, and what does it provide?
How do u pass data from one jsp to another jsp?