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 Integer 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.

4
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 Integer 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.

LANGUAGE: JAVA

CHALLENGE:

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 Integer 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.

SOLUTION:


public Clock (int hours, boolean isTicking, int diff){
   this.hours = hours;
   this.isTicking = isTicking;
   this.diff = new Integer (diff);
}

4 comments

Add comment