diff --git a/source/ch6_definingclasses.ptx b/source/ch6_definingclasses.ptx index 4adb2ff..df7a4af 100644 --- a/source/ch6_definingclasses.ptx +++ b/source/ch6_definingclasses.ptx @@ -627,8 +627,26 @@ public class Fraction { } + +

+ If you ran , 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 Fraction objects. + Just like in Python, whenever an object is printed by the println method it must be converted to string format. + In Python you can control how that looks by writing an __str__ method for your class. + If you do not then you will get the default, which looks something like . We will see how to provide a friendly string representation for our Fraction class in . +

+

@@ -672,35 +690,11 @@ public class Fraction { - -

Inheritance - -

- 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 Fraction objects. - Just like in Python, whenever an object is printed by the println method it must be converted to string format. - In Python you can control how that looks by writing an __str__ method for your class. - If you do not then you will get the default, which looks something like the above. -

-
- - The <c>Object</c> Class