Wrapper classes represents the primitive values as objects. All of the wrapper classes except Character have 2 constructors; one which takes the primitive value and the other which takes the string representation of the value.
So in your code,
Integer b = new Integer(15);
it takes in the primitive int value. Here 15 is the integer number here. The same can be done by giving String as argument, Integer b = new Integer("15");
//2 how it prints the object value where a object of single member variable is not printing in line //6
Here, in line 2, it is not printing the object value, it is passing the primitive value(pass by value), whereas in line 6 B b1 = new B(1000); //5 System.out.println(b1); //6 you are creating an instance of the class B, so it gives the class name followed by @ symbol, followed by unsigned hexadecimal representation of the objects code.
FYI, it is not printing the number 10, which you are passing, compile and try with other nums.
Wrapper objects are immutable. This means that once a wrapper object has a value assigned to it, that value cannot be changed Hope, this answers all your questions.
Because a hash code value for the Wrapper object, equal to the primitive(int)value represented by the Wrapper(Integer) object.
Joined: Jan 15, 2007
I have complied the code in java 1.5 it is error free
Thank you for your replies but still I have some confusion...
in line //3 b is also the instance of of Integer class so it should print the reference value like other object!!! But Why it is printing the value of the object? Is there any deference between simole Object and wrapper class object.... Please make me understand...