1.2 当没有任何构造函数,java编译器,会插入一个默认的构造函数
见下面的例子:
class Line {
double x = 0.02;
double y;
}
public class Test {
public static void main(String[] args) {
Line c = new Line();
System.out.println(c.x);
System.out.println(c.y);
}
}
class Circle1 {
double x = 0.02;
double y;
public Circle1(){
}
}
public class Test {
public static void main(String[] args) {
Circle1 c = new Circle1();
System.out.println(c.x);
System.out.println(c.y);
}
}
更多请见:http://www.mark-to-win.com/tutorial/java_2_InsertDefaultConstructor.html