Let's say we have a class as follows:
public class Time{
int hour;
int min;
Time(int hour,int m){
hour=h;
min=m;
}
public String toString(){
return hour+":"+min;
}
}
And I want to write some code like this in main with results as in the comments:
Time t1 = new Time(13,45);
Time t2= new Time(12,05);
System.out.println(t1>=t2); // true
System.out.println(t1<t2); // false
System.out.println(t1+4); // 17:45
System.out.println(t1-t2); // 1:40
System.out.println(t1+t2); // 1:50 (actually 25:50)
System.out.println(t2++); // 13:05
Can I do that by interfaces etc. or the only thing I can do is to write methods instead of using operators?
Thanks in advance.