我正努力尋找如何通過另一種靜態方法發送/訪問已在主要方法中創建的對象。如何訪問在主要方法中創建的對象
這裏是我的我的一些服務類的代碼,它由公共構造函數,訪問和mutator方法:
public class Participants
{
String firstName=" ";
String lastName=" ";
int socialSecurity=0;
int ticket=0;
char status='N';
Vehicle veh=null;
public Participants(String fn, String ln, int ssn, int tkt)
{
firstName=fn;
lastName=ln;
socialSecurity=ssn;
ticket=tkt;
}
}
還有就是客戶端類,它有在那裏我創建和初始化的主要方法對象和第二方法,我試圖訪問這些對象:
public class Race
{
public static void main(String[] args)
{
....
Participants []people=new Participants[35];
Vehicle []cars=new Vehicle[10];
...code to "fill" those objects
GiveAway([]cars,[]people); //sending those objects to static method- doesn't work from here)
}
public static void GiveAway(Vehicle[] veh, Participants[] part)
{
//set of instructions to work and change those objects
}
}
的代碼根本不工作,那是因爲我真的不知道如何可以「送」的對象數組的方法(順便說一下,這可能嗎?)。
我正確的做法嗎?或者有更簡單的方法?我發現了一些關於私人課程和其他一些內容的主題,但無法弄清楚如何處理我的代碼。
我很感謝任何幫助
謝謝!