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
{{ message }}
Repository navigation
Commit 3d14e42
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: source/ch_7_definingclasses.ptx
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -233,7 +233,7 @@ public Fraction(Integer num, Integer den) {
233
233
<p>
234
234
Now we come to one of the major differences between Java and Python.
235
235
The Python class definition used the special methods for addition and comparison that have the effect of redefining how the standard operators behave: in Python, <c>__add__</c> and <c>__lt__</c> change the behavior of <c>+</c> and <c><</c>, respectively.
236
-
In Java there is <term>no operator overloading</term>.
236
+
In Java there is no operator overloading.
237
237
So we will have to write the method for addition a little differently.
238
238
</p>
239
239
@@ -248,12 +248,12 @@ public Fraction(Integer num, Integer den) {
248
248
<ul>
249
249
<li>
250
250
<p>
251
-
<term>Java is strictly pass-by-value.</term> For primitive types (like <c>int</c>), a copy of the value is passed. For object types (like our <c>Fraction</c>), a copy of the <em>value of the reference</em> (the memory address) is passed.
251
+
<idx>pass-by-value</idx><term>Java is strictly pass-by-value.</term> For primitive types (like <c>int</c>), a copy of the value is passed. For object types (like our <c>Fraction</c>), a copy of the <em><idx>value of the reference</idx><term>value of the reference</term></em> (the memory address) is passed.
252
252
</p>
253
253
</li>
254
254
<li>
255
255
<p>
256
-
<term>Python is pass-by-assignment</term> (or pass-by-object-reference). Since everything in Python is an object, the rule is consistent: a copy of the reference to the object is passed.
256
+
<idx>pass-by-assignment</idx><term>Python is pass-by-assignment</term> (or pass-by-object-reference). Since everything in Python is an object, the rule is consistent: a copy of the reference to the object is passed.
257
257
</p>
258
258
</li>
259
259
</ul>
@@ -282,7 +282,7 @@ public Fraction add(Fraction otherFrac) {
282
282
</program>
283
283
284
284
<p>
285
-
First you will notice that the <c>add</c> method is declared as <c>public Fraction</c> The <c>public</c> part means that any other method may call the <c>add</c> method.
285
+
First you will notice that the <c>add</c> method is declared as <c>public Fraction</c> The <c><idx>public</idx><term>public</term></c> part means that any other method may call the <c>add</c> method.
286
286
The <c>Fraction</c> part means that <c>add</c> will return a fraction as its result.
287
287
</p>
288
288
@@ -333,14 +333,14 @@ public Fraction add(Fraction otherFrac) {
333
333
<p>
334
334
In Java we can do runtime type checking, but the compiler will not allow us to pass an Integer to the <c>add</c> method since the parameter has been declared to be a Fraction.
335
335
The way that we solve this problem is by writing another <c>add</c> method with a different set of parameters.
336
-
In Java this practice is legal and common we call this practice <term>method overloading</term>.
336
+
In Java this practice is legal and common we call this practice <idx>method overloading</idx><term>method overloading</term>.
337
337
</p>
338
338
339
339
<p>
340
340
This idea of method overloading raises a very important difference between Python and Java.
341
341
In Python a method is known by its name only.
342
342
In Java a method is known by its signature.
343
-
The signature of a method includes its name, and the types of all of its parameters.
343
+
The <idx>signature</idx><term>signature</term> of a method includes its name, and the types of all of its parameters.
344
344
The name and the types of the parameters are enough information for the Java compiler to decide which method to call at runtime.
0 commit comments