Skip to content

Commit 9657237

Browse files
committed
added listing tags
1 parent d2798a2 commit 9657237

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

source/ch6_definingclasses.ptx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,8 @@ public void test(Number a, Number b) {
769769
Here is an excerpt from <url href="https://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html#compareTo(T)" visual="https://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html#compareTo(T)">the official documentation</url> for the <c>compareTo</c> method as specified by the <c>Comparable</c> interface.
770770
</p>
771771

772-
773-
<program xml:id="java-comparable" language="text">
772+
<listing xml:id="java-comparable">
773+
<program language="text">
774774
<code>
775775
int compareTo(T o)
776776
Compares this object with the specified object for order. Returns a
@@ -782,27 +782,29 @@ iff y.compareTo(x) throws an exception.)
782782
...
783783
</code>
784784
</program>
785+
</listing>
785786

786787
<p>
787788
To make our <c>Fraction</c> class <c>Comparable</c> we must modify the class declaration line as follows:
788789
</p>
789790

790-
791-
<program xml:id="java-make-comparable" language="java">
791+
<listing xml:id="java-make-comparable">
792+
<program language="java">
792793
<code>
793794
public class Fraction extends Number implements Comparable&lt;Fraction&gt; {
794795
...
795796
}
796797
</code>
797798
</program>
799+
</listing>
798800

799801
<p>
800802
The specification <c>Comparable&lt;Fraction&gt;</c> makes it clear that <c>Fraction</c> is only comparable with another <c>Fraction</c>.
801803
The <c>compareTo</c> method could be implemented as follows:
802804
</p>
803805

804-
805-
<program xml:id="java-comparable2" language="java">
806+
<listing xml:id="java-comparable2">
807+
<program language="java">
806808
<code>
807809
public int compareTo(Fraction other) {
808810
Integer num1 = this.numerator * other.getDenominator();
@@ -811,8 +813,11 @@ public int compareTo(Fraction other) {
811813
}
812814
</code>
813815
</program>
816+
</listing>
817+
814818
</section>
815819

820+
816821
<section xml:id="static-member-variables">
817822
<title>Static member variables</title>
818823

0 commit comments

Comments
 (0)