Skip to content

Commit 2c3343d

Browse files
committed
feat: Track student info using instance and static variables in School class [school-static-instance-vars]
🔑 Key: school-static-instance-vars 🧠 Logic & Features: - Created a `School` class that holds: • `studentName` (instance variable) – unique for each object • `rollNumber` (instance variable) – assigned incrementally per student using static counter • `schoolName` (static variable) – shared across all students • `totalStudents` (static variable) – keeps track of how many students have been created - Constructor: • Assigns name and auto-increments the roll number using `++totalStudents`. - Methods: • `display()` – non-static method to print individual student info • `displayTotalStudents()` – static method to print total number of students created 📌 Key Concepts: - ✅ **Instance Variables**: • Belong to each object; different for each student. - ✅ **Static (Global) Variables**: • `schoolName` is shared and same for all. • `totalStudents` is used as a counter to give unique roll numbers. - ✅ **Static Methods**: • Used when logic is related to the class itself, not specific to any object. - ✅ **Constructor**: • Helps auto-assign unique roll numbers using a global counter. Signed-off-by: Somesh diwan <[email protected]>
1 parent f7c53cd commit 2c3343d

File tree

1 file changed

+1
-1
lines changed
  • Section10Methods/LocalandGlobalVariables/src

1 file changed

+1
-1
lines changed

Section10Methods/LocalandGlobalVariables/src/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ public static void main(String[] args) {
4141

4242
School.displayTotalStudents();
4343
}
44-
}
44+
}

0 commit comments

Comments
 (0)