3段階目

This commit is contained in:
m-shimizu
2026-09-16 13:42:09 +09:00
parent b3fd66606d
commit 23f5358254
2 changed files with 18 additions and 5 deletions

View File

@@ -1,15 +1,21 @@
public class BasicCheck2 { public class BasicCheck2 {
public static void main(String[] args) { public static void main(String[] args) {
Student student = new Student(1,"鈴木一郎");
student.studentId = 1; Student student1 = new Student(1,"鈴木一郎");
student.name = "鈴木一郎"; Student student2 = new Student(2,"田中花子");
Student student3 = new Student(3,"佐藤次郎");
// student.studentId = 1;
// student.name = "鈴木一郎";
// System.out.print("学籍番号"+student.studentId); // System.out.print("学籍番号"+student.studentId);
// System.out.print("名前:" + student.name); // System.out.print("名前:" + student.name);
student.printProfile(); student1.printProfile();
student2.printProfile();
student3.printProfile();
System.out.println("現在の生徒数:" + Student.getStudentCount() + "人");
} }
} }

View File

@@ -2,11 +2,15 @@
public class Student { public class Student {
int studentId; int studentId;
String name; String name;
static int studentCount = 0;
public Student(int studentId, String name) { public Student(int studentId, String name) {
this.studentId = studentId; this.studentId = studentId;
this.name = name; this.name = name;
studentCount++;
} }
public void printProfile() { public void printProfile() {
@@ -17,7 +21,10 @@ public class Student {
//s.printProfile(); //s.printProfile();
//} //}
public static int getStudentCount() {
return studentCount;
}
} }