public class Constructor1 {
private String str = "nihao";
private String str1 = null;
private String str2 = str1;
Constructor1(String s){
this.str1 = s;
}
public static void main(String[] args) {
Constructor1 c = new Constructor1("Hello World");
System.out.println("构造函数初始化后的String域" + c.str1);
System.out.println("类定义的String域" + c.str);
System.out.println("构造器运行前的String域" + c.str2);
}
}
不同初始化String域方式的差别: