java - How to access a array in a instance -
i making card game , have following section of code (a small excerpt):
hand[] hands; hands = new hand[t]; (i = 1; > t; i++) { hands[i] = new hand(); } public class hand { hand() { card[] hand; hand = new card[52]; } } how access array in hand object?
for example, let's had instance of hand class called hand1, how access array hand in hand1 object?
doing hand1.hand[x] did not work.
hand() { card[] hand; hand = new card[52]; } card[] hand local variable you're declaring inside hand() constructor. if want use variable should declare globally so:
private card[] hand; hand() { hand = new card[52]; } and have getter & setter methods retrieve private variable (this called 'encapsulation'). don't think there's need those
Comments
Post a Comment