/** * TestFraction class * * This class demonstrates the difference between using * == with an object, and using an equals() method. * * @author Erica Eddy * @version December 2010 */ public class TestFraction { public static void main(String [] args) { // create 2 fraction objects with identical contents Fraction first = new Fraction(1,2); Fraction second = new Fraction(1,2); // Fraction second = first; // compare memory addresses if (first == second) System.out.println("first and second are =="); else System.out.println("first and second are not =="); // compare contents if ( first.equals(second) ) System.out.println("first and second are equal"); else System.out.println("first and second are different"); } }