首页 > 代码库 > this关键字
this关键字
class emp{private int empno ; private String ename; private String job ; private double sal ; public emp(){ this(1,"张三","前台",100); } public emp (int empno){ this(empno,"李四","后台",2000); } public emp(int empno,String ename){ this(empno,ename,"程序员",10000); } public emp(int empno,String ename,String job,double sal){ this.empno=empno; this.ename=ename; this.job=job; this.sal=sal; } public String getInfo(){ return "编号"+this.empno+",姓名:"+ this.ename+ ",职位:" + this.job + ",工资:" + this.sal ; }}public class indone{public static void main(String args[]){ emp ea = new emp(); emp eb = new emp(2); emp ec = new emp(3,"德玛西亚"); emp ed = new emp(4,"上帝","万能的程序员",50000); System.out.println(ea.getInfo()); System.out.println(eb.getInfo()); System.out.println(ec.getInfo()); System.out.println(ed.getInfo()); }}this一定要放在构造方法的首行
this关键字
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。