Java Reference
In-Depth Information
{
return (hr == otherClock.hr
&& min == otherClock.min
&& sec == otherClock.sec);
}
//Method to copy time
//Postcondition: The instance variables of otherClock
// copied into the corresponding data
// are members of this time.
// hr = otherClock.hr;
// min = otherClock.min;
// sec = otherClock.sec;
public void makeCopy(Clock otherClock)
{
hr = otherClock.hr;
min = otherClock.min;
sec = otherClock.sec;
}
//Method to return a copy of time
//Postcondition: A copy of the object is created and
// a reference of the copy is returned
public Clock getCopy()
{
Clock temp = new Clock();
temp.hr = hr;
temp.min = min;
temp.sec = sec;
return temp;
}
}
In a class definition, it is a common practice to list all the instance variables, named constants,
other datamembers, or variable declarations first, then the constructors, and then themethods.
Once a class is properly defined and implemented, it can be used in a program. A program
or software that uses and manipulates the objects of a class is called a client of that class.
EXAMPLE 8-2
//Program to test various operations of the class Clock
import java.util.*;
public class TestProgClock
 
Search WWH ::




Custom Search