posted 11 years ago
Hi,
I'm trying to build an array of object references in a class called "PersonTest" that reference a class called "Person". Class "Person" has a variable "String name" and an array "String[] friends". Once I've created this array of object references, however, I can't seem to get the friends array of that respective object. It only returns the most recently created object's friends array. I use an object reference in class "PersonTest" to call the getFriends method contained in class "Person" to get a respective persons friends by using "people[x].getFriends()[]" but it only accesses the last object created regardless of the index "x". Please find code below. It includes extensive print statements that I hope illustrates what I'm trying to do. Thank you in advance for your help.
This is the output:
BEGIN OUTPUT
asdf
qwer
bubba
Lucy
Jimmy
Bart
Fand
Fart
Burp
Base
Ball
Frog
Turt
Funny
Sock
Stiff
----
Turt
Funny
Sock
Stiff
----
Turt
Funny
Sock
Stiff
----
Turt
Funny
Sock
Stiff
----
Turt
Funny
Sock
Stiff
END OUTPUT
I would like the output to be:
BEGIN OUTPUT
asdf
qwer
bubba
Lucy
Jimmy
Bart
Fand
Fart
Burp
Base
Ball
Frog
Turt
Funny
Sock
Stiff
----
asdf
qwer
bubba
Lucy
----
Jimmy
Bart
Fand
Fart
----
Burp
Base
Ball
Frog
----
Turt
Funny
Sock
Stiff
END OUTPUT