Hi.......
Ques: I have create a String object as below String str = "abc" & String str = new String("abc") Why can not a button object be created as Button bt = "abc"? Why is it compulsory to create a button object as Button bt = new Button("abc")? Why this is not compulsory in String's case? please explain...
Loading

Satyapriya NayakPosted Dec 14, 2011, 12:04 PM
String is not just another class in Java. There are a lot of special cases in String class. If you
notice carefully, String is an Immutable class where as that's not true for Button or most of the other
classes. Java compiler as well as '+' and '+=' operators convert quoted characters in to String. I
believe Java designers wanted to treat Strings as close to primitive types as possible and hence some
of the differences.
Important to not that you are NOT calling a java.lang.String constructor when you type String s =
"abc"; for example:
String x = "abc";
String y = "abc";
refer to the same object.
While
String x1 = new String ("abc");
String x2 = new String ("abc");
refer to two different objects.
Refer
http://technical-interview.com/In_Java_You_can_create_a_String_object_as_below.aspx
Thanks
VulpesPosted Dec 14, 2011, 11:56 AM
http://www.c-sharpcorner.com/Forums/Thread/152170/i-am-create-a-string-object-as-below.aspx