wood burning stoves 2.0*
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


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

objects

Gregor Pavlic
Greenhorn

Joined: Sep 12, 2012
Posts: 1
Hello...

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??

Thanks...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37936
    
  22
No.


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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: objects
 
Similar Threads
"dummy" code
Alpha beta pruning with negamax
Problem in looping
can anyone explain the flow of the code
Recursive method to print prime factorization of a number