Allocate memory for array of Objects.
Hello,
I'm confused how to allocate memory for an array, if its members are Objects...
I tried to create a class CardDeck, which will represent an array of objects of Card class.
And I get Quote:
Syntax error on token ";", , expected
error, when I'm trying to allocate memory like that:
Code:
package app;
class CardDeck {
Card[] cards;
static final int deckSize = 36;
cards = new Card[deckSize - 1];
/*
* new CardDeck constructor, creates a new CardDeck object
*/
CardDeck(){
int k = 0;
for (int i=0; i<4; i++){
for (int j=0; j<8; j++){
cards[k] = new Card(Card.suites[i], Card.rates[j]);
k++;
}
}
}
/*
* Outputs all deck cards
*/
void getDeckDetails(){
for(int k = 0; k < (deckSize - 1); k++){
this.cards[k].getCardDetails();
}
}
I read in the tutorial this lines:
int[] anArray;
anArray = new int[10]
and tried to behave like it was in example.