定义一个时钟类Clock,用属性时、分、秒来表示时间, 在构造方法中对属性进行初始化,成员方法printTime 用于显示时钟对象的时间。定义主类TestClock,在主 类的main方法中创建多个时钟
public class Clock {
int hours;
int minutes;
int seconds;
public Clock(int hours, int minutes, int seconds) {
super();
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
}
void printTime(){
System.out.println(hours+":"+minutes+":"+seconds);
}
}
package gh;
public class text7 {
public static void main(String[] args) {
Clock myClock1=new Clock(8,3,32);
Clock myClock2=new Clock(12,5,2);
myClock1.printTime();
myClock2.printTime();
}
}
