首页 > 代码库 > 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关键字