码迷,mamicode.com
首页 > 其他好文 > 详细

this关键字

时间:2016-09-08 18:28:37      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:

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关键字

标签:

原文地址:http://www.cnblogs.com/shuaiqiyang/p/5853913.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!