Given the following declaration
Integer i=new Integer(99);
How can you now set the value of i to 10?
1) i=10;
2) i.setValue(10);
3) i.parseInt(10);
4) none of the above
Answer 4: none of the above
The wrapper classes are immutable. Once the value has been set it cannot be changed. A common use of the wrapper classes is to take advantage of their static methods such as Integer.parseInt(String s) that will returns an integer if the String contains one.
No comments:
Post a Comment