-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasics14.java
More file actions
36 lines (26 loc) · 783 Bytes
/
Basics14.java
File metadata and controls
36 lines (26 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package irene;
class Student {
String name;
static int studentCount = 0;
Student(String name) {
this.name = name;
studentCount++;
}
public void getStudentDetails() {
System.out.println("Name: " + name);
}
public static int getStudentCount() {
return studentCount;
}
}
public class Basics14 {
public static void main(String[] args) {
Student student1 = new Student("Alice");
Student student2 = new Student("Bob");
Student student3 = new Student("Charlie");
student1.getStudentDetails();
student2.getStudentDetails();
student3.getStudentDetails();
System.out.println("Total number of students: " + Student.getStudentCount());
}
}