Java object-oriented--------time jobs

Source: Internet
Author: User

Write Java applications. First, define a clock class--clock, which consists of three int types

Member variables represent hours, minutes, seconds, and a construction method for three member variables (hours, minutes, seconds)

for initialization, there is also a member Method show () to display the time of the clock object. Second, redefine

a main class ,testclass, creates objects of multiple clock classes in the main method of themaster Class , using this

Some objects call the method Show () to display the time of the clock.

Package Liu0918;public class Clock {int hour;int minutes;int seconds;int Show; Clock (int h,int m,int s) {hour=h;minutes=m;seconds=s;} int Getshow () {System.out.println (the current time is: "+hour+" when "+minutes+" minutes "+seconds+" seconds "); return show; int Gethour () {return hour;} int getminutes () {return minutes;} int getseconds () {return seconds;}}


Package Liu0918;public class TestClass {public static void main (string[] args) {clock c=new clock (23,51,24); System.out.println ("Current Time:" +c.gethour () + "Time" +c.getminutes () + "Min" +c.getseconds () + "seconds"); Clock c1=new clock (10,11,12); C1.getshow (); Clock c2=new clock (22,22,22); C2.getshow ();}}


Java object-oriented--------time jobs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.