Ask Question
2 August, 00:36

You are given a class named Clock that has three instance variables: One of type int called hours, another of type boolean called isTicking, and the last one of type int called diff. Write a constructor for the class Clock that takes three parameters-an int, a boolean, and another int. The constructor should set the instance variables to the values provided.

public Clock () {

int hours, diff;

boolean isTicking;

}

+4
Answers (1)
  1. 2 August, 04:19
    0
    Clock (int hours, boolean isTicking, int diff) / / constructor clock

    {

    this. hours = hours;

    / / set the instance variable hours

    this. isTicking = isTicking;

    / / set the boolean variable isTicking

    this. diff = diff;

    //set the instance variable diff

    }

    Explanation:

    Here we declared a constructor clock which has 3 parameter hours, boolean isTicking, and diff.

    The int hours, diff is of int type and isTicking is of boolean type. In this constructor, we set the instance variables values by using this keyword.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “You are given a class named Clock that has three instance variables: One of type int called hours, another of type boolean called ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers