This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "objects" Watch "objects" New topic


Gregor Pavlic

Joined: Sep 12, 2012
Posts: 1

I'm new here and I need help...
If I create objects like this...

Can I access the data for individual object, or can't I??

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 43898

Welcome to the Ranch
What you are doing is creating each object inside the loop, and not keeping a variable (at least not in the code shown) which points to it outside the loop. When you get to the end of the loop, player points to the last‑created object.
Maybe you meant to keep the Player objects in a List or an array. Maybe the addPlayerInfo method does keep a copy of all their references.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: objects
It's not a secret anymore!