Skip to content

Commit 1e73df0

Browse files
authored
Merge pull request #322 from habibasorour/issue_314_listing
Issue 314 fixed: listing in 6.6
2 parents 8adc49a + aca8781 commit 1e73df0

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

source/ch6_definingclasses.ptx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -841,11 +841,11 @@ public int compareTo(Fraction other) { // compare this fraction with another fra
841841
Suppose that you wanted to write a Student class so that the class could keep track of the number of students it had created.
842842
Although you could do this with a global counter variable that is an ugly solution.
843843
The right way to do it is to use a <c>static</c> variable.
844-
In Python, we could do this as follows:
844+
<xref ref="python-static-member-variable" text="type-global"/> shows how to do this in Python.
845845
</p>
846846

847-
848-
<program xml:id="python-static" interactive="activecode" language="python">
847+
<listing xml:id="python-static-member-variable">
848+
<program interactive="activecode" language="python">
849849
<code>
850850
class Student:
851851
numStudents = 0
@@ -860,13 +860,14 @@ def main():
860860
main()
861861
</code> <tests> </tests>
862862
</program>
863+
</listing>
863864

864865
<p>
865-
In Java, we would write this same example using a <c>static</c> declaration.
866+
<xref ref="java-static-member-variable" text="type-global"/> shows how to do this in Java.
866867
</p>
867868

868-
869-
<program xml:id="java-static" interactive="activecode" language="java">
869+
<listing xml:id="java-static-member-variable">
870+
<program interactive="activecode" language="java">
870871
<code>
871872
public class Student {
872873
public static Integer numStudents = 0;
@@ -886,10 +887,11 @@ public class Student {
886887
}
887888
</code> <tests> </tests>
888889
</program>
890+
</listing>
889891

890892
<p>
891893
<idx>static member variable</idx>
892-
In this example notice that we create a <term>static member variable</term> by using the <c>static</c> modifier on the variable declaration. Once a variable has been declared <c>static</c> in Java it can be accessed from inside the class without prefixing the name of the class as we had to do in Python.
894+
In <xref ref="java-static-member-variable" text="type-global"/>, notice that we create a <term>static member variable</term> by using the <c>static</c> modifier on the variable declaration. Once a variable has been declared <c>static</c> in Java it can be accessed from inside the class without prefixing the name of the class as we had to do in Python.
893895
</p>
894896
</section>
895897

0 commit comments

Comments
 (0)