Write Java applications. First, define a clock class-clock, which consists of three int member variables representing hours, minutes, seconds, and a construction method to initialize three member variables (hours, minutes, seconds). There is also a member method show () time to display the clock object. Next, define a main class,TestClass, to create objects of multiple clock classes in the main method of themaster class , using these objects to invoke the method show () to display the time of the clock.
int shi;int fen;int miao;public clock () {}public clock (int newshi,int newfen,int newmiao) {Shi=newshi; Fen=newfen; Miao=newmiao; System.out.println ("The time of the construction method clock is" +newshi+ ":" +newfen+ ":" +newmiao);} void Show () {System.out.println ("The time of the member method clock is" +shi+ ":" +fen+ ":" +miao);}
public static void Main (string[] args) {clock clock1=new clock (2,3,4); Clock clock2=new clock (); clock2.shi=7; clock2.fen=8; clock2.miao=9; Clock2.show ();}
Run results
Java Object-oriented exercises 3