Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7006695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:30:37+00:00 2026-05-27T21:30:37+00:00

I have 2 classes . The one is about a 24 hour clock and

  • 0

I have 2 classes . The one is about a 24 hour clock and the second one is a subclass of the first and is a 12 hour clock.
To convert the new time in second class i need to change the value of the first class. But i can’t do that.
I am talking about “h” variable
Specifically…

    class Clock{
    public int h, m , s;
    public String a,b,c;

    public void setHour(int hour){
        this.h = hour;
    }
    public void setMin(int min){
        this.m = min;
    }
    public void setSec(int sec){
        this.s = sec;
    }
    public void tick(){ 
        if(h != 23){
            if(m == 59 && s==59){
                m = 0;
                s=0;
                h++;
            }
            else if(m != 59 && s == 59){
                m++;
                s=0;
            }
            else if ( m != 59 && s != 59){
                s++;
            }
            else if( m == 59 && s!=59){
                s++;
            }
        }

        else if(h == 23 && m == 59 && s !=59){
            s++;
        }
        else if(h == 23 && m!=59 && s == 59){
            s=0;
            s++;
            m++;
        }
        else if(h == 23 && m!=59 && s!=59){
            s++;
        } 
        else if(h == 23 && m == 59 && s == 59){
            s = 0;
            m =0;
            h = 0;
        }
    }
    public String toString(){ 
        a = "";
        b = "";
        c = "";

        if (h < 10)
            a = "0";
        if (m <10 )
            b = "0";
        if (s <10)
            c = "0";

        return a+h+":"+b+m+":"+c+s;
    }
}

   class AMPMClock extends Clock{
    Clock clock2 = new Clock();
    public void setAMPM(boolean yes){
        if(yes == true){
            **clock2.h = clock2.h - 12**;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:30:38+00:00Added an answer on May 27, 2026 at 9:30 pm

    Your AMPMClock should either just extend Clock or just use it. But you are trying to combine them both as follows:

    class AMPMClock extends Clock {
        Clock clock2 = new Clock();
    

    Either extend:

    class AMPMClock extends Clock {
    

    Because, the public accesor methods are inherited, you can invoke getter/setter methods on this. e.g. this.getHour().

    Or use it but don’t extend:

    class AMPMClock {
        Clock clock2 = new Clock();
    

    Here, instead of this use clock2. e.g. clock2.getHour().

    But, you need to make all the instance members private (they should not to be public). And make corresponding public getter/setter for all of them.

    As suggested by dasblinkenlight:

    It would be better to have an abstract class:

    public abstract class BaseClock {
        private int h, m, s;
        //getter/setter
    }
    

    And two different concrete classes:

    public class TwelveHourClock extends BaseClock { }
    

    and

    public class TwentyFourHourClock extends BaseClock { }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two basic questions. The first one is about function in other classes.
I have some classes that, for one reason or another, cannot be or need
I have two classes, and want to include a static instance of one class
First I want to describe my situation briefly. I have two classes, one MainClass
I have got two classes, one a subclass of the other (say Animal and
I have one abstract class and many child classes. In child classes are from
I have classes like this one: class SomeObject { public function __construct($param1, $param2) {
I have two classes, one of which is a subclass of another, and differs
I have 4 classes, one Database helper and 3 defined like this: abstract class
I have three classes, one class loads in a configuration file into memory for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.