• Post Reply Bookmark Topic Watch Topic
  • New Topic

Object Arrays  RSS feed

 
Richard West
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

Please bear with me for a while as i need to ask a rather silly question.

Does anyone know how to decalre an object of arrays with arguments.

See the below code



The above program obviously does not compile because of the below line



My question is basically how to i declare it as an array of 5.

Sorry again for the silly question.

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
 
John Dell'Oso
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard,

Try this:

JTest[] a = new JTest[5];

You will then hit another problem - but I'll leave that up to you to try and figure out.

Regards,
JD
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Richard West:
...Sorry again for the silly question...

There are no "silly" questions in the beginners forum. That's why we're here!

John's suggestion above will create a new array that can hold 5 references to JTest objects. (Note that when you create an array, its size is set and cannot be changed.) In this example, the 5 references will each be initialzed to null. Now it's up to you to assign these to reference JTest instances.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!