1.首先创建好一个类,里面可以暂时有2个属性。
public class GeometricObject {
protected String color;
protected double weight;
}
2. 鼠标在编辑区右击,弹出对话框,点击generate
,或者是使用快捷键Alt + Insert
。

3. 选择自动生成构造器
或者是set()
和get()
方法点击即可。

4. 选中类中的color
和weight
两个属性,点击OK
即可生成。

5. 包括构造器在内的一些方法都可以自动生成了。
public class GeometricObject {
protected String color;
protected double weight;
public GeometricObject(String color, double weight) {
this.color = color;
this.weight = weight;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
}