java中自动插入一个默认的构造函数,这到底怎么回事?
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);
}
}
更多内容请见原文,原文转载自:https://blog.csdn.net/qq_44639795/article/details/103751002