例如我有一堂课
第一类:
public class car{
private Color carColor;
public car(Color carColor)
{
this.carColor = carColor;
}
public void setColor(Color carColor)
{
this.carColor = carColor;
}
}
类2:
public class car{
private Color carColor;
public car(Color carColor)
{
setColor(carColor);
}
public void setColor(Color carColor)
{
this.carColor = carColor;
}
}
哪个构造函数将是 Java 编码的最佳实践,为什么?