代码如下:

public class Person { private String sex; private static double min_salary;

public String getSex() {
    return sex;
}

public void setSex(String sex) {
    this.sex = sex;
}

public static double getMin_salary() {
    return min_salary;
}

public static void setMin_salary(double min_salary) {
    Person.min_salary = min_salary;
}

public static void main(String[] args) {
    Person m1 = new Person();
    Person m2 = new Person();

    m1.setSex("男");
    Person.setMin_salary(6000.0);

    System.out.println("m1的性别为:" + m1.getSex() + ",最低工资为:" + Person.getMin_salary());
    System.out.println("m2的性别为:" + m2.getSex() + ",最低工资为:" + Person.getMin_salary());
}
在当前类中定义两个私有属性:性别sex字符串和最低工资min_salary实型其中最低工资额为静态属性。2、分别为这两个属性编写读取和设置访问器方法;3、编写main方法创建该类的对象m1和m24、通过设置方法设置m1对象性别为男5、通过类名属性名设置最低工资为600006、分别输出m1和m2对象的两个属性的值。

原文地址: https://www.cveoy.top/t/topic/eHBs 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录