Hi:
All,there is a question :
1.How many
String objects are created when the following class is run?
Code ��
public class TestClass {
public static void main(String args[]) {
String hello = "Hello"; //1
String world = new String("World!");//2
String helloworld = hello +" "+world;//3
String alias = helloworld ; //4
System.out.println(alias); //5
}
}
I think there is only 5 object!
//1 has one in literal pool "Hello",
//2 has two ,one is in programm space,other is in literal pool,
//3 "" is one , the last is "Hello World!" as helloworld reference ! So only 5 ! But tha answer is 6 !
Who can tell me Why ? Thanks,very!!