I'm currently having a self-study with java, watching thenewboston's vids. I coded a constructor just like his code but I'm getting an error.
Here's my complete code in another.java
NOTE: THE SCREENSHOT ABOVE AND THE CODES BELOW DOES NOT HAVE THE SAME NAME OF CLASS, I JUST CHANGED IT BECAUSE IT CONFUSED ME. HOPE YOU UNDERSTAND
public class class2{
private int hour;
private int minutes;
private int second;
public class2(){
this(0,0,0); /** It says "recursive constructor incovation class2(int,int,int)" */
}
public class2(int h){
this(h,0,0); /** It says "recursive constructor incovation class2(int,int,int)" */
}
public class2(int h, int m){
this(h,m,0); /** It says "recursive constructor incovation class2(int,int,int)" */
}
public class2(int h, int m, int s){
this(h,m,s); /** It says "recursive constructor incovation class2(int,int,int)" */
}
public void setTime(int h, int m, int s){
setHour(h);
setMinute(m);
setSecond(s);
}
public void setHour(int h){
hour = ((h >=0 && h <24) ? h : 0);
}
public void setMinute(int m){
minutes = ((m >=0 && m <60) ? m : 0);
}
public void setSecond(int s){
second = ((s >=0 && s <60) ? s : 0);
}
public int getHour (){
return hour;
}
public int getMinute (){
return minutes;
}
public int getSecond(){
return second;
}
public String printTime(){
return String.format("%02d:%02d:%02d:", getHour(),getMinute(),getSecond());
}
}
The error it says is "recursive constructor incovation class2(int,int,int)" If you have an answer, kindly explain it also. Thanks!