This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Array overwritten Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array overwritten" Watch "Array overwritten" New topic
Author

Array overwritten

Rob Brew
Ranch Hand

Joined: Jun 23, 2011
Posts: 99
Hi all.


I'm building a version of battleships, two arrays are created, x and y, when added to the array list Ships. When i run the program i get the same variables appearing in each instance of the array. Any ideas?
Ryan Beckett
Ranch Hand

Joined: Feb 22, 2009
Posts: 192
The member x of each instance of Ship refers to same array instance created in init(). It's the same for y. You need to create a new ones.

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Array overwritten
 
Similar Threads
InputStreamReader returns null
problem with arrays and paint
java.util.ConcurrentModificationException
Calling seperate functions
Battleships - guys please help me out!