diff --git a/source/ch6_definingclasses.ptx b/source/ch6_definingclasses.ptx index c1b2d6f..3450de8 100644 --- a/source/ch6_definingclasses.ptx +++ b/source/ch6_definingclasses.ptx @@ -766,11 +766,11 @@ public void test(Number a, Number b) {

The Comparable interface says that any object that claims to be Comparable must implement the compareTo method. - Here is an excerpt from the official documentation for the compareTo method as specified by the Comparable interface. + Here is an excerpt from the official documentation for the compareTo method as specified by the Comparable interface. shows the excerpt.

- - + + int compareTo(T o) Compares this object with the specified object for order. Returns a @@ -782,27 +782,29 @@ iff y.compareTo(x) throws an exception.) ... +

- To make our Fraction class Comparable we must modify the class declaration line as follows: + To make our Fraction class Comparable we must modify the class declaration line as shown in .

- - + + public class Fraction extends Number implements Comparable<Fraction> { ... } +

The specification Comparable<Fraction> makes it clear that Fraction is only comparable with another Fraction. - The compareTo method could be implemented as follows: + The compareTo method could be implemented as shown in .

- - + + public int compareTo(Fraction other) { Integer num1 = this.numerator * other.getDenominator(); @@ -811,8 +813,11 @@ public int compareTo(Fraction other) { } + + +
Static member variables