我想將3種類型的5個對象傳遞給數組列表。當我打印清單時,所有的值都是零。我試過修改對象類型,但仍然沒有結果,任何人都可以幫忙嗎?將對象傳遞給ArrayList Java
//Item is a Class by itself and the 5 objects draw from this but will have 2/3 additional parameters
ArrayList<Item> inventory = new ArrayList<>();
//Item 1
Dvd dvd1 = new Dvd(1234567, 2001, "Sugar were going down", "15", "Comedy DVD", 2, 180, "Japanese");
//Item 2
Dvd dvd2 = new Dvd(7654321, 2005, "The only way is up!", "12A", "Comedy DVD", 3, 220, "Greek, Spanish, Italian");
等等。現在我的輸出是這樣的:
ID: 0
Year: 0
Title:
Classification:
Genre:
Return Date: 25/5/2014
Available: true
有什麼建議?
代碼添加對象:
inventory.add(dvd1);
inventory.add(dvd2);
打印代碼:
for(int i = 0; i<= inventory.size(); i++){
System.out.println(inventory.get(i));
}
您可以發佈的[MCVE(http://stackoverflow.com/help/mcve)顯示你如何打印的東西出來? –
請添加您輸出的代碼和插入項目 – Neso
請勿在代碼中張貼代碼。編輯您的問題並添加相關內容。 –