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 |
What a static class can contains?
10. class Nav{ 11. public enum Direction { NORTH, SOUTH, EAST, WEST } 12. } 13. public class Sprite{ 14. // insert code here 15. } Which code, inserted at line 14, allows the Sprite class to compile? a)Direction d = NORTH; b)Nav.Direction d = NORTH; c)Direction d = Direction.NORTH; d)Nav.Direction d = Nav.Direction.NORTH;
How does JAVA ClassLoader work?
What is the base class for error and exception?
What is lexicographically smallest string?
What is a lightweight component?
Hai friends I am MCA 2006 passout. Spend time in 1 yr for teacing and 5 months in small s/w firm. worked in 4 or 5 months in few places. Presently I am writing bank exams. I want to get back to IT sector. Are there any possibilities. any growth prospects?. I am having some knowledge in core and advanced java. I am so desperate. Any suggestions thanks in advance. u can write to my mail mahidestiny@gmail.com
What is the difference between assignment and initialization?
public class Base { public void myMethod(int a,intb) {} } // Uses myMethod and then hides it. public class DerivedOne extends Base { private void myMethod(int a,int b); } will this compile or not .yes or no. why
What is the difference between scrollbar and scrollpane?
What is javac used for?
What do you mean by synchronized non access modifier?