class Time {
private int hour;
private int minute;
private int second;
private static int count = 0;
public Time() {
this(0, 0, 0);
}
public Time(int hour, int minute, int second){
this.hour = hour;
this.minute = minute;
this.second = second;
count++;
}
public String getInfo() {
return "Time:" + this.hour + ":" + this.minute + ":" + this.second;
}
public void setHour(int hour) {
this.hour = hour;
}
public void setMinute(int minute) {
this.minute = minute;
}
public void setSecond(int second) {
this.second = second;
}
public int getHour() {
return this.hour;
}
public int getMinute() {
return this.minute;
}
public int getSecond() {
return this.second;
}
public static int getCount(){ //获取时间对象个数
return count;
}
}
public class JavaDemo{
public static void main(String[] args) {
Time firstTime = new Time();
System.out.println(firstTime.getInfo());
Time chinaTime = new Time(20, 26, 40);
System.out.println(chinaTime.getInfo());
chinaTime.setMinute(40);
System.out.println("minute:" + chinaTime.getMinute());
System.out.println(chinaTime.getInfo());
System.out.println("时间对象个数:" + Time.getCount());
}
}
//运行结果
Time:0:0:0
Time:20:26:40
minute:40
Time:20:40:40
时间对象个数:2