Skip to content

Commit 08a99d5

Browse files
authored
Merge pull request #305 from habibasorour/issue_297_list
Issue 297 fixed: listing added
2 parents 513eb15 + 7c86b21 commit 08a99d5

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

source/ch6_definingclasses.ptx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,19 @@ public void setDenominator(Integer denominator) { // setter method
220220
In Java, <term>constructors</term> have the same name as the class and are declared public.
221221
They are declared without a return type.
222222
So any method that is named the same as the class and has no return type is a constructor.
223-
Our constructor will take two parameters: the numerator and the denominator.
223+
Our constructor will take two parameters: the numerator and the denominator. <xref ref="java-fraction-constructor" text="type-global"/> shows the constructor for the <c>Fraction</c> class.
224224
</p>
225225

226-
227-
<program xml:id="java-fraction-constructor" language="java">
226+
<listing xml:id="java-fraction-constructor">
227+
<program interactive="activecode" language="java">
228228
<code>
229229
public Fraction(Integer top, Integer bottom) {
230230
num = top;
231231
den = bottom;
232232
}
233233
</code>
234234
</program>
235+
</listing>
235236

236237
<p>
237238
<idx><c>this</c></idx>
@@ -241,18 +242,19 @@ public Fraction(Integer top, Integer bottom) {
241242
This allows the Java compiler to do the work of dereferencing the current Java object.
242243
Java does provide a special variable called <c>this</c> that works like the <c>self</c> variable.
243244
In Java, <c>this</c> is typically only used when it is needed to differentiate between a parameter or local variable and an instance variable.
244-
For example this alternate definition of the the Fraction constructor uses <c>this</c> to differentiate between parameters and instance variables.
245+
For example,<xref ref="java-fraction-constructor" text="type-global"/> shows an alternate definition of the the Fraction constructor that uses <c>this</c> to differentiate between parameters and instance variables.
245246
</p>
246247

247-
248-
<program xml:id="java-fraction-class-this" language="java">
248+
<listing xml:id="java-fraction-class-this">
249+
<program interactive="activecode" language="java">
249250
<code>
250251
public Fraction(Integer num, Integer den) {
251252
this.num = num;
252253
this.den = den;
253254
}
254255
</code>
255256
</program>
257+
</listing>
256258
</section>
257259

258260
<section xml:id="methods">

0 commit comments

Comments
 (0)