java 笔记 this关键字与构造函数

 public String toString()
    {
        return "Emp [empno=" + empno + ", ename=" + ename + ", job=" + job + ", sal=" + sal + "]";
    }
    public Emp()
    {
        this(-1, "无名氏", "未指定", 0);
    }
    public Emp(long empno)//接收参数,通过this调用其他构造函数并传递参数
    {
        this(empno,"无名氏","未指定",0);
    }
    public Emp(long empno, String name)
    {
        this(empno, name, "未指定", 0);
    }
    
    public Emp(long empno, String ename, String job, float sal)
    {
        super();
        this.empno = empno;
        this.ename = ename;
        this.job = job;
        this.sal = sal;
    }

你可能感兴趣的:(java 笔记 this关键字与构造函数)