Java—构造方法get和set,私有属性调用
2021-03-13
私有属性 标志 【private】
其它.java文件调用需要 先实体化类,new 一个对象
并通过 对象名.set和对象名.set 获取和设置
私有属性文件中 按 alt+insert ,选择【set和get】一键创建好get和set方法

import com.sun.org.apache.bcel.internal.generic.NEW; public class Scanner01 { public static void main(String[] args) { Sduty01 sduty01 = new Sduty01(); sduty01.setHaha("???"); System.out.println(sduty01.getHaha()); } }
public class Sduty01 { private String haha; private int age; private int num; public String getHaha() { return haha; } public void setHaha(String haha) { this.haha = haha; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public int getNum() { return num; } public void setNum(int num) { this.num = num; } }

浙公网安备 33010602011771号