1.首先创建好一个类,里面可以暂时有2个属性。

public class GeometricObject {
    protected String color; // protected 可以被子类访问
    protected double weight;
}

2. 鼠标在编辑区右击,弹出对话框,点击generate,或者是使用快捷键Alt + Insert

在这里插入图片描述

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

在这里插入图片描述

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

在这里插入图片描述

5. 包括构造器在内的一些方法都可以自动生成了。

public class GeometricObject {
    protected String color; // protected 可以被子类访问
    protected double weight;

    // ctrl + / 是注释多行
    // ctrl + shift + / 是 注释代码块
//    protected GeometricObject(String color, double weight){
//        this.color = color;
//        this.weight = weight;
//    }


    public GeometricObject(String color, double weight) {
        this.color = color;
        this.weight = weight;
    }


    // 自动生成 get 和 set 方法
    // 右键  generator
    // 或者是 alt + insert 快捷键

    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;
    }
}

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐