Thursday, March 12, 2009

You can create a String object as String str = "abc"; Why cant a button

Question :You can create a String object as String str = "abc"; Why cant a button
object be created as Button bt = "abc";? Explain (CoreJava)

Answer :The main reason you cannot create a button by Button bt1= "abc"; is
because "abc" is a literal string (something slightly different than a String
object, by-the-way) and bt1 is a Button object. The only object in Java that
can be assigned a literal String is java.lang.String. Important to note that
you are NOT calling a java.lang.String constuctor when you type String s =
"abc";

No comments: