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 a static class can contains?

0 Answers  


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;

2 Answers  


How does JAVA ClassLoader work?

1 Answers   IBM,


What is the base class for error and exception?

0 Answers  


What is lexicographically smallest string?

0 Answers  






What is a lightweight component?

0 Answers  


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

4 Answers  


What is the difference between assignment and initialization?

0 Answers  


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

2 Answers  


What is the difference between scrollbar and scrollpane?

0 Answers  


What is javac used for?

0 Answers  


What do you mean by synchronized non access modifier?

0 Answers  


Categories