关于构造方法
public class Mystery {
private String s;
public void Mystery() { //不是构造方法
s = "constructor";
}
void go() {
System.out.println(s);
}
public static void main(String[] args) {
Mystery m = new Mystery();
m.go();
}
}以上程序的打印结果为什么为null。
public class Mystery {
private String s;
public void Mystery() { //不是构造方法
s = "constructor";
}
void go() {
System.out.println(s);
}
public static void main(String[] args) {
Mystery m = new Mystery();
m.go();
}
}以上程序的打印结果为什么为null。
2016-07-19
举报