Recursive Constructor Invocation

前端 未结 3 1686
执笔经年
执笔经年 2020-12-11 10:16
public class LecturerInfo extends StaffInfo {

    private float salary;

    public LecturerInfo()
    {
        this();
        this.Name = null;
        this.Addr         


        
3条回答
  •  猫巷女王i
    2020-12-11 10:57

    the code below is recursive. Since this() will call no arg constructor of current class that means LectureInfo() again.

    public LecturerInfo()
    {
        this(); //here it translates to LectureInfo() 
        this.Name = null;
        this.Address = null;
        this.salary=(float) 0.0;
    }
    

提交回复
热议问题