|
LQ Newbie
Registered: May 2004
Posts: 17
Rep:
|
Java help (accessing array elemonts from another class or method)
Ok basically I have my main Method which is where I have initialized an array of objects. I want to access this array, the objects within and the actual methods within the object from within another class. How would I go about doing this???
I keep on coming up with errors.
Here is some of my code to help you...
public static void main(String[]args)
{
//Declare Variables
int menuChoice = 2;
boolean quit = false;
// Init carArry and set variables
Car [] carArray;
carArray = new Car [10];
//Possition In Array Manufact Model E.Size Reg Millage MPG Status
carArray[0] = new Car("Vauxhall", "Corsa", 1.3, "GP 03 CBT", 8123, 35, 'Y');
carArray[1] = new Car("Vauxhall", "Agila", 1.2, "AB 03 FTR", 10045, 38, 'S');
carArray[2] = new Car("Vauxhall", "Agila", 1.0, "FT 01 YUT", 21488, 40, 'N');
carArray[3] = new Car("Vauxhall", "Astra", 1.6, "RT 51 DRE", 15032, 32, 'S');
carArray[4] = new Car("Vauxhall", "Astra", 2.2, "DR 51 KLP", 19933, 25, 'Y');
carArray[5] = new Car("Ford", "Fiesta", 1.0, "GP 53 REW", 4987, 40, 'Y');
carArray[6] = new Car("Ford", "Fiesta", 1.3, "SR 01 BHG", 1997, 35, 'N');
carArray[7] = new Car("Ford", "Mondeo", 1.6, "WE 02 GTY", 17342, 33, 'N');
carArray[8] = new Car("Ford", "Mondeo", 2.0, "QW 52 EWQ", 12345, 25, 'Y');
carArray[9] = new Car("Ford", "Orion", 1.8, "SD 01 TYR", 24459, 28, 'N');
}
Also here is one method from my Car object..
// Read the millage attribute
public double getMillage()
{
return millage;
}
How would I go about accessing this method from another class???
Thanks alot...
|