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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -