Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions source/ch6_definingclasses.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public void setDenominator(Integer denominator) {
<title>Writing a constructor</title>

<p>
<idx>constructor</idx>
Once you have identified the instance variables for your class the next thing to consider is the constructor.
In Java, <term>constructors</term> have the same name as the class and are declared public.
They are declared without a return type.
Expand All @@ -207,7 +208,7 @@ public void setDenominator(Integer denominator) {
<program xml:id="java-fraction-constructor" language="java">
<code>
public Fraction(Integer top, Integer bottom) {
num = top;
num = top; // notice the use of num instead of top
den = bottom;
}
</code>
Expand All @@ -228,7 +229,7 @@ public Fraction(Integer top, Integer bottom) {
<program xml:id="java-fraction-class-this" language="java">
<code>
public Fraction(Integer num, Integer den) {
this.num = num;
this.num = num; // notice how we use this.num instead of num
this.den = den;
}
</code>
Expand Down