144k views
2 votes
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 !

User Radu Linu
by
7.4k points

1 Answer

2 votes
I guess you need it written in Java. So if you need only constructor, then here it is:
public Clock(Clock clock1) {
this.hours = clock1.hours;
this.isTicking = clock1.isTicking;
}

This code is 100% correct
User Kulodo
by
8.1k points