-1

I get the recursive construct overflow invocation error at the four public tuna parts (parts=maybe a class or something else?). It worked on the tutorial but not for me and can't seem to see where

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){
        this(h,m,s);    //with hours, minutes and seconds
    }
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
user3752231
  • 75
  • 2
  • 9

2 Answers2

7

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;
}
John
  • 896
  • 7
  • 25
  • sorry im working on java. so if i change that how should i output it for the this(0,0,0) since it has no variables? – user3752231 Jun 18 '14 at 11:34
  • Sorry if I didn't get you right, but you just have to change the tuna(int h, int m, int s) constructor as I said. Everything else should be fine. – John Jun 18 '14 at 11:37
-2
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 
Tanvi
  • 1