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
Once you have identified the instance variables for your class the next thing to consider is the constructor.
220
220
In Java, <term>constructors</term> have the same name as the class and are declared public.
221
221
They are declared without a return type.
@@ -278,8 +278,8 @@ public Fraction(Integer num, Integer den) {
278
278
<li>
279
279
<p>
280
280
<idx>pass-by-value</idx>
281
-
<idx>value of the reference</idx>
282
-
<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><term>value of the reference</term></em> (the memory address) is passed.
281
+
282
+
Java is strictly <term>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 <term>reference</term>(Namely, the memory address) is passed.
283
283
</p>
284
284
</li>
285
285
<li>
@@ -571,7 +571,7 @@ public String toString() {
571
571
In Java, when two objects are compared using the <c>==</c> operator they are tested to see if they are exactly the same object (that is, do the two objects occupy the same exact space in the computer’s memory?).
572
572
This is also the default behavior of the <c>equals</c> method provided by <c>Object</c>.
573
573
The <c>equals</c> method allows us to decide if two objects are equal by looking at their instance variables.
574
-
However it is important to remember that since Java does not have operator overloading <term>if you want to use your</term> <c>equals</c> <term>method you must call it directly</term>.
574
+
However it is important to remember that since Java does not have operator overloading <em>if you want to use your</em> <c>equals</c> <em>method you must call it directly</em>.
575
575
Therefore once you write your own <c>equals</c> method:
576
576
</p>
577
577
@@ -631,7 +631,7 @@ public boolean equals(Fraction other) {
631
631
If you look at the documentation for <c>Integer</c> you will see that <c>Integer</c>’s parent class is <c>Number</c>.
632
632
Number is an <term>abstract class</term> that specifies several methods that all of its children must implement.
633
633
In Java an abstract class is more than just a placeholder for common methods.
634
-
In Java an abstract class has the power to specify certain methods that all of its children <term>must</term> implement.
634
+
In Java an abstract class has the power to specify certain methods that all of its children <em>must</em> implement.
635
635
You can trace this power back to the strong typing nature of Java.
636
636
</p>
637
637
@@ -650,7 +650,7 @@ public class Fraction extends Number {
650
650
</listing>
651
651
652
652
<p>
653
-
<idx><c>extends</c></idx>
653
+
<idx><c>extending a class</c></idx>
654
654
The keyword <term><c>extends</c></term> tells the compiler that the class <c>Fraction</c> extends, or adds new functionality to the <c>Number</c> class.
655
655
A child class always extends its parent.
656
656
</p>
@@ -720,7 +720,7 @@ public long longValue() {
720
720
</p>
721
721
722
722
<p>
723
-
However, and this is a big however, it is important to remember that if you specify <c>Number</c> as the type of a particular parameter then the Java compiler will <term>only let you use the methods of a</term> <c>Number</c>: <c>longValue</c>, <c>intValue</c>, <c>floatValue</c>, and <c>doubleValue</c>.
723
+
However, and this is a big however, it is important to remember that if you specify <c>Number</c> as the type of a particular parameter then the Java compiler will <em>only let you use the methods of a</em> <c>Number</c>: <c>longValue</c>, <c>intValue</c>, <c>floatValue</c>, and <c>doubleValue</c>.
724
724
</p>
725
725
726
726
<p>
@@ -739,7 +739,7 @@ public void test(Number a, Number b) {
739
739
740
740
<p>
741
741
The Java compiler would give an error because <c>add</c> is not a defined method of the <c>Number</c> class.
742
-
You will <term>still get this error</term> even if all your code that calls this <c>test</c> method passes two <c>Fractions</c> as parameters (remember that <c>Fraction</c> does implement <c>add</c>).
742
+
You will <em>still get this error</em> even if all your code that calls this <c>test</c> method passes two <c>Fractions</c> as parameters (remember that <c>Fraction</c> does implement <c>add</c>).
743
743
</p>
744
744
</subsection>
745
745
</section>
@@ -748,7 +748,6 @@ public void test(Number a, Number b) {
748
748
<title>Interfaces</title>
749
749
750
750
<p>
751
-
<idx><c>Comparable</c></idx>
752
751
<idx>single inheritance</idx>
753
752
Lets turn our attention to making a list of fractions sortable by the standard Java sorting method <c>Collections.sort</c>.
754
753
In Python, we would just need to implement the <c>__cmp__</c> method.
0 commit comments