I don't understand how I read an array that is coming into a method. I could have any number for the array size so need the for loop. But what does Vehicle @765291 mean? Is is the place stored in memory, if so something must be coming in and if so I do I get the String value? Do I cast it? And if so why is this necessary?

The version of System.out.println() that takes an Object as a parameter calls toString() on that Object and prints out the resultant String. The default Object.toString() implementation returns a String object with the name of the concrete class for the object and the address of the object (at least, I think that's what the number represents). If you want to print out more meaningful information, you need to override the toString() object in the classes you write. In this case, simply add a toString() method to your Vehicle class that creates a String with the information you wish to display.

will only ever be used in conjunction with an array. Its a special "method" for getting the contents the array contains at the place the index points to. Because the object Vehicle is not (and never can be) an array, this is why you get the "array required, but Vehicle found" message.

Take a look at some array-like Collection classes (java.util.ArrayList, java.util.LinkedList, java.util.Vector). All of these have methods to access the data they contain in a simmilar way - e.g. ArrayList uses get(int index). If you want your printArray method to print the contents of an array of Vehical objects, it will have to take an array in as its parameter like this:

If your Vehicle class contains an array of data you want to print, you will have to supply a simmilar accessor method as you find in ArrayList, LinkedList or Vector. You will also have to give it a publicly accessable property of length. Then you could do something like you want:

Originally posted by Layne Lund: The default Object.toString() implementation returns a String object with the name of the concrete class for the object and the address of the object (at least, I think that's what the number represents).

Actually, the number is the hash code of the object. The hash code of any object that doesn't override it, is related to the identity of the object, which is related to the address. As the hash code is always 32 bits (an int), but Java is not constrained to run on 32-bit machines, it is wrong to say that the hash code is the address.

Here's Object.toString(): -

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.