我的代码打印 0 而不是大小和年份。我究竟做错了什么?基本上我希望它返回那些,但我不确定我在做什么。
public class House {
private int year;
private int size;
private static int nbrOfHouses;
public static final int MIN_SIZE =10;
public House(int _year,int _size){
_year = year;
_size = size;
}
public static int getNbrHouses(){
return nbrOfHouses;
}
public int getYear(){
return year;
}
public int getSize(){
return size;
}
}
House[] myHouse = new House[10];{
myHouse[0] = new House(1902, 120);
myHouse[1] = new House(1954, 180);
myHouse[2] = new House(1995,90);
for(int i=0; i< myHouse.length; i++){
if(myHouse[i]!=null){
System.out.println(myHouse[i].getYear());