Overblog Tous les blogs Top blogs Technologie & Science Tous les blogs Technologie & Science
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

java array

13 Avril 2013 Publié dans #java

在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};

Publicité
Partager cet article
Repost0
Pour être informé des derniers articles, inscrivez vous :
Commenter cet article