java array
在java类中,添加一个数组作为成员,以及如何实例化这个类。并把几个实例化的对象存在一个数组内。
public class Hotel {
private String hotelId;
private String hotelName;
private int numberRooms;
private int[] numberRest = new int[364];
public Hotel(){};
public Hotel(String hotelId, String hotelName, int numberRooms)
{
this.hotelId=hotelId;
this.hotelName=hotelName;
this.numberRooms=numberRooms;
for(int i=0;i<364;i++)
{
this.numberRest[i]=numberRooms;
}
}
}
Hotel hotel0 = new Hotel("000","hotel0",100);
Hotel hotel1 = new Hotel("001","hotel1",50);
Hotel hotel2 = new Hotel("002","hotel2",20);
Hotel hotellist[]={hotel0,hotel1,hotel2};