[필드-2] Student, School

seratpfk·2022년 7월 27일
0

JAVA

목록 보기
41/96

class : Student (메인메소드 없음)

String stuNo;
String name;

class : School (메인메소드 없음)

String name;
Student[] students = new Student[2];  // {null, null}

class : SchoolMain (메인메소드 설정)

School school = new School();
school.name = "경인중학교";
Student student1 = new Student();
student1.name = "전지현";
student1.stuNo = "11025";
Student student2 = new Student();
student2.name = "정우성";
student2.stuNo = "11026";
school.students[0] = student1;	// school.students[i]에 값을 지정함.
school.students[1] = student2;	
for(int i = 0; i < school.students.length; i++) {
	System.out.println(school.students[i].stuNo);
	System.out.println(school.students[i].name);
}

0개의 댓글