Recursive constructor invocation error can't find solution

扶醉桌前 提交于 2019-12-02 14:24:02

You're doing a recursive call here:

public tuna(int h, int m, int s){
    this(h,m,s);    //with hours, minutes and seconds
}

You should set your private members in this constructor. It should be something like:

public tuna(int h, int m, int s){
    this.h = h;    //with hours, minutes and seconds
    this.m = m;
    this.s = s;
}
public tuna(int h, int m, int s){
    this(h,m,s);    //with hours, minutes and seconds
}

Insead of this(h,m,s); use setTime(h,m,s);

It should be:

public class tuna {
    private int hour;
    private int minute;
    private int second;

    public tuna() {
        this(0,0,0); //default  
    }
    public tuna(int h){
        this(h,0,0);    //with hours input
    }
    public tuna(int h, int m){
        this(h,m,0);    //with hours and minutes
    }
    public tuna(int h, int m, int s){
        setTime(h,m,s);    //with hours, minutes and seconds
    }  
   // define setTime method below 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!