From f48fa0e6de1db9d41e126342f352d45400e5f182 Mon Sep 17 00:00:00 2001 From: Habiba Sorour Date: Mon, 3 Aug 2026 18:29:27 +0300 Subject: [PATCH 1/3] added comments to code --- source/ch6_definingclasses.ptx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/ch6_definingclasses.ptx b/source/ch6_definingclasses.ptx index 9ad5051..d3632f8 100644 --- a/source/ch6_definingclasses.ptx +++ b/source/ch6_definingclasses.ptx @@ -836,13 +836,13 @@ public int compareTo(Fraction other) { class Student: numStudents = 0 - def __init__(self, id, name): + def __init__(self, id, name): self.id = id self.name = name - Student.numStudents = Student.numStudents + 1 + Student.numStudents = Student.numStudents + 1 # increment the static variable def main(): for i in range(10): - s = Student(i,"Student-"+str(i)) + s = Student(i,"Student-"+str(i)) // create a new student print('Number of students:', Student.numStudents) main() @@ -856,13 +856,13 @@ main() public class Student { - public static Integer numStudents = 0; + public static Integer numStudents = 0; // static member variable, shared by all instances of the class private int id; private String name; public Student(Integer id, String name) { this.id = id; this.name = name; - numStudents = numStudents + 1; + numStudents = numStudents + 1; // a static variable, that can be accessed without the Student prefix } public static void main(String[] args) { for(Integer i = 0; i < 10; i++) { From ef74077384e65e04efaf3b2b0419a070c074ee88 Mon Sep 17 00:00:00 2001 From: Habiba Sorour Date: Mon, 3 Aug 2026 18:32:35 +0300 Subject: [PATCH 2/3] fixed a comment --- source/ch6_definingclasses.ptx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/ch6_definingclasses.ptx b/source/ch6_definingclasses.ptx index d3632f8..0c04a74 100644 --- a/source/ch6_definingclasses.ptx +++ b/source/ch6_definingclasses.ptx @@ -839,10 +839,10 @@ class Student: def __init__(self, id, name): self.id = id self.name = name - Student.numStudents = Student.numStudents + 1 # increment the static variable + Student.numStudents = Student.numStudents + 1 # this is a static variable, that can be accessed without the self prefix def main(): for i in range(10): - s = Student(i,"Student-"+str(i)) // create a new student + s = Student(i,"Student-"+str(i)) # create a new Student object print('Number of students:', Student.numStudents) main() From 7002f82269f189aa11d1bad03060ae46ed010c2a Mon Sep 17 00:00:00 2001 From: Habiba Sorour Date: Mon, 3 Aug 2026 18:33:25 +0300 Subject: [PATCH 3/3] fixed a comment --- source/ch6_definingclasses.ptx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/ch6_definingclasses.ptx b/source/ch6_definingclasses.ptx index 0c04a74..1573906 100644 --- a/source/ch6_definingclasses.ptx +++ b/source/ch6_definingclasses.ptx @@ -839,7 +839,8 @@ class Student: def __init__(self, id, name): self.id = id self.name = name - Student.numStudents = Student.numStudents + 1 # this is a static variable, that can be accessed without the self prefix + # this is a static variable, that can be accessed without the self prefix + Student.numStudents = Student.numStudents + 1 def main(): for i in range(10): s = Student(i,"Student-"+str(i)) # create a new Student object