重写属性的set和get方法,怎么写
1个回答
展开全部
通常在构造函数中使用get和set,目的是用来初始化成员变量,代码参考如下 package Day02; public class Dept { private String dname; private String loc; private int deptno; public Dept() { super(); } public Dept(String dname, String loc) { super(); this.dname = dname; this.loc = loc; } public Dept(int deptno,String dname, String loc) { super(); this.deptno = deptno; this.dname = dname; this.loc = loc; } public int getDeptno() { return deptno; } public void setDeptno(int deptno) { this.deptno = deptno; } public String getDname() { return dname; } public void setDname(String dname) { this.dname = dname; } public String getLoc() { return loc; } public void setLoc(String loc) { this.loc = loc; } }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询