4월 28일 내용 정리
내부 클래스 & 배열
package study_0428_04;
public class Hotel01 {
class Room{ //내부클래스
String list[]=new String[10]; //1~10번 공간만들기
}
Room r =new Room(); //내부클래스 객체생성
//메서드
void add(int num,String name) { //인자 받기
r.list[num-1]=name; //내부클래스의 배열 불러서 이름 넣기
}
void show() {
for(int i=0;i<r.list.length;i++) {//for문을 통해서 내부클래스의 배열 내용 모두출력
if(r.list[i]!=null) { //if문 통해서 내용이 있으면 출력, null이면 암것도 출력안함.
System.out.println(i+1+"번 방을 "+r.list[i]+"가 예약했습니다.");
}
}
}
}
실행 클래스
package study_0428_04;
public class HotelTest01 {
public static void main(String[] args) {
Hotel01 myHotel= new Hotel01();
myHotel.add(5, "호돌이");
myHotel.add(7, "길동이");
myHotel.show();
}
}