Possible Duplicate:
How to declare an array in Java?
Suppose I have an object car (class vehicle) and I want to create an array of N number of cars . How do I declare that in Java?
vehicle[N]= car=new vehicle [];
Is this right?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s the other way round:
This makes more sense, as the number of elements in the array isn’t part of the type of
car, but it is part of the initialization of the array whose reference you’re initially assigning tocar. You can then reassign it in another statement:(Note that I’ve changed the type name to match Java naming conventions.)
For further information about arrays, see section 10 of the Java Language Specification.