diff --git a/source/ch6_definingclasses.ptx b/source/ch6_definingclasses.ptx index 9ad5051..599f0d8 100644 --- a/source/ch6_definingclasses.ptx +++ b/source/ch6_definingclasses.ptx @@ -217,6 +217,7 @@ public void setDenominator(Integer denominator) { // setter method
- If you ran the program above you probably noticed that the output is not very satisfying. Chances are your output looked something like this:
+ If you ran the program above you probably noticed that the output is not very satisfying. Chances are your output looked something like
Fraction@6ff3c5b5
The reason is that we have not yet provided a friendly string representation for our
We are not interested in most of the methods on that list, and many Java programmers live happy and productive lives without knowing much about most of the methods on that list.
- However, to make our output nicer we will implement the
public String toString() {
return numerator.toString() + "/" + denominator.toString();
}
+
object1 == object2
- is NOT the same as:
+
object1.equals(object2)
- Here is an
public boolean equals(Fraction other) {
Integer num1 = this.numerator * other.getDenominator();
@@ -616,6 +621,7 @@ public boolean equals(Fraction other) {
}
One important thing to remember about
- Here is code that makes the
public class Fraction extends Number {
...
}
-
- This really isn’t much work for us to implement these methods, as all we have to do is some type conversion and some division:
+ This really isn’t much work for us to implement these methods, as all we have to do is some type conversion and some division as shown in
public double doubleValue() {
return numerator.doubleValue() / denominator.doubleValue();
@@ -710,6 +717,7 @@ public long longValue() {
}
- However, and this is a big however, it is important to remember that if you specify
- Suppose you try to define a method as follows:
+ Suppose you try to define a method as
public void test(Number a, Number b) {
a.add(b);
}
The Java compiler would give an error because
-