
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); }
I dont understand this can someone plz explain why “this.” is used??
public class Clock
{
private int hours;
}
Clock (int hours, boolean isTicking, int diff){
this.hours = hours;
this.isTicking = isTicking;
this.diff = diff;
}
public Clock(int h, boolean tick, int d)
{
hours = h;
isTicking = tick;
diff = d;
}