Skip to content

Commit f48fa0e

Browse files
committed
added comments to code
1 parent 55d59bb commit f48fa0e

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

source/ch6_definingclasses.ptx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -836,13 +836,13 @@ public int compareTo(Fraction other) {
836836
<code>
837837
class Student:
838838
numStudents = 0
839-
def __init__(self, id, name):
839+
def __init__(self, id, name):
840840
self.id = id
841841
self.name = name
842-
Student.numStudents = Student.numStudents + 1
842+
Student.numStudents = Student.numStudents + 1 # increment the static variable
843843
def main():
844844
for i in range(10):
845-
s = Student(i,"Student-"+str(i))
845+
s = Student(i,"Student-"+str(i)) // create a new student
846846
print('Number of students:', Student.numStudents)
847847
main()
848848
</code> <tests> </tests>
@@ -856,13 +856,13 @@ main()
856856
<program xml:id="java-static" interactive="activecode" language="java">
857857
<code>
858858
public class Student {
859-
public static Integer numStudents = 0;
859+
public static Integer numStudents = 0; // static member variable, shared by all instances of the class
860860
private int id;
861861
private String name;
862862
public Student(Integer id, String name) {
863863
this.id = id;
864864
this.name = name;
865-
numStudents = numStudents + 1;
865+
numStudents = numStudents + 1; // a static variable, that can be accessed without the Student prefix
866866
}
867867
public static void main(String[] args) {
868868
for(Integer i = 0; i &lt; 10; i++) {

0 commit comments

Comments
 (0)