Hi Preeti: The output would be 'False'. The reasoning behind is that the b1.toString() would return a String object each time and we all know that if we use '==' on 2 String objects they would not be equal (until and unless they were constructed using the same literal, however thats not the case here) Hope the above helps. Fazal
Hi Fazal, Byte b1 = new Byte("127"); //line if(b1.toString() == b1.toString()) System.out.println("True"); else System.out.println("False");
in place of line 1 if u change String b1 = new String("Java"); it will print True. Why ? diff behavior betn Byte(Wrapper class) and String. i think in String : b1.toString() return same obj ref.
Joined: Mar 06, 2001
Hi Arvind: Quite true; if you call the toString() on a String object, it would return itself i.e. a String object. However, if you call the toString() on a Byte object, it would return a new String object representing the Byte object's value. Fazal