You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/ch6_definingclasses.ptx
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -277,7 +277,7 @@ public Fraction(Integer num, Integer den) {
277
277
However, if you reassign the parameter to a completely new object inside the method (e.g., <c>otherFrac = new Fraction(0,1);</c>), it would <em>not</em> affect the original variable outside the method, because you are only changing the local copy of the reference.
278
278
</p>
279
279
<p>
280
-
Let’s begin by implementing addition in Java:
280
+
<xrefref="java-fraction-class-addition-initial"text="type-global"/> shows the first part of the Fraction class definition.
@@ -302,7 +302,7 @@ public Fraction add(Fraction otherFrac) {
302
302
<p>
303
303
Second, you will notice that the method makes use of the <c>this</c> variable.
304
304
In this method, <c>this</c> is not necessary, because there is no ambiguity about the <c>numerator</c> and <c>denominator</c> variables.
305
-
So the following version of the code is equivalent:
305
+
<xrefref="java-fraction-class-addition-equivalent"text="type-global"/> is an equivalent version of <xrefref="java-fraction-class-addition-initial"text="type-global"/>.
@@ -364,7 +364,7 @@ public Fraction add(Fraction otherFrac) {
364
364
To solve the problem of adding an <c>Integer</c> and a <c>Fraction</c> in Java we will overload both the constructor and the <c>add</c> method.
365
365
We will overload the constructor so that if it only receives a single <c>Integer</c> it will convert the <c>Integer</c> into a <c>Fraction</c>.
366
366
We will also overload the <c>add</c> method so that if it receives an <c>Integer</c> as a parameter it will first construct a <c>Fraction</c> from that integer and then add the two <c>Fractions</c> together.
367
-
The new methods that accomplish this task are as follows:
367
+
<xrefref="java-method-overloading"text="type-global"/> shows the new methods that accomplish this task.
0 commit comments