标准JavaBean

标准 J a v a B e a n \huge{标准JavaBean} 标准JavaBean

解释

其实标准 J a v a B e a n JavaBean JavaBean就是实体类,显示生活中存在的实体类,也可以理解为一种约束格式。它的对象可以在程序中封装数据。

书写格式

①. 内部成员变量使用private进行修饰,提高安全性。
②. 必须有配套的getter and setter方法。
③. 必须有一个无参数的构造器,有参数的可以没有。

样例

public class User {

	//成员变量全部私有化
    private double height;
    private String name;
    private double salary;
    private String address;
    private String phone;

    public User() {
    }


	//❗在Idea中右键点击generate可以自动生成有参无参构造器和相应的getter与setter

    public User(double height, String name, double salary, String address, String phone) {
        this.height = height;
        this.name = name;
        this.salary = salary;
        this.address = address;
        this.phone = phone;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
}

你可能感兴趣的:(Java,java,intellij-idea,ide)