为什么不是 类名.变量名 = new 类名();
public Circle() {
color = new Color();
}
为什么标准答案显示:构造函数的代码块必须放在类的开头?如:
public class Circle {
public Color color;
public Circle() {
color = new Color();
}
public static void main(String[] args) {
Circle circle = new Circle();
circle.color.setDescription("红色");
System.out.println(circle.color.getDescription());
}
public class Color {
String description;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}