A class named Clock has two instance variables : hours (type int ) and isTicking (type boolean ). Write a constructor that takes a reference to an existing Clock object as a parameter and copies that object ‘s instance variables to the object being created.

LANGUAGE: JAVA

CHALLENGE:

A class named Clock has two instance variables : hours (type int ) and isTicking (type boolean ). Write a constructor that takes a reference to an existing Clock object as a parameter and copies that object ‘s instance variables to the object being created.

Your task: Write a Clock constructor that makes this possible. Just write this constructor — don’t write the whole class or any code outside of the class !

SOLUTION:

public Clock(Clock a)
{
    hours = a.hours;
    isTicking = a.isTicking;
}