我有一個10個對象的數組,我想初始化他們的數組。如何初始化數組的對象?
private Flight[] flight = new Flight[10];
flight[0] = new Flight("AA101", "Boston", "Sacremento", 421.33, 22, 6);
flight[1] = new Flight("AA102", "Lincolin", Jacksonville, 612.08, 22 6);
flight[2] = new Flight("AA103", "Rochester", "Columbia", 510.83, 22, 6);
flight[3] = new Flight("AA104", "Boise", "Aspen", 411.12, 22, 6);
flight[4] = new Flight("AA105", "Fort Collins", "Louiseville", 654.22, 22, 6);
flight{5} = new Flight("AA106", "Seattle", "Dallas" 326.14, 22, 6);
flight{6} = new Flight("AA107", "Phoenix", "Little Rock", 974.22, 22, 6);
flight[7] = new Flight("AA108", "Cheyenne", "Louiseville", 521.43 , 22, 6);
flight[8] = new Flight("AA109", "Louiseville", "Buffalo", 452.21, 22, 6);
flight[9] = new Flight("AA100", "Anchorage" , "Tampa", 874.72, 22, 6);
,但我得到噸的錯誤,如:
ReservationGUI.java:31: error: ']' expected
ReservationGUI.java:31: error: illegal start of type
ReservationGUI.java:31: error: ';' expected
ReservationGUI.java:31: error: expected
有他們的100。
'Jacksonville'應該有引號,除非它引用變量的地方 – JonK
移動所有這些這些線(除了第一個)的一些方法(或構造函數)內 – Eran
葉蘭可能你詳細說明我們的方法,我不喜歡改變我的代碼,除非我完全明白我爲什麼要以某種方式做到這一點 –