Edit:
Main method…
creates a new player.
Player class…
creates an instance of hand.
Hand class…
creates an arraylist
thats all. its pretty simple
public class Player
{
/*------------------------
* instantiating variable
-----------------------*/
protected Hand hand;
protected boolean active = false;
/*------------
* constructor
-----------*/
public Player()
{
hand = new Hand();
hand.setSize(5);
}
public class Hand extends Player
{
/*-----------------------------------------
* variable declaration
----------------------------------------*/
ArrayList <Card> hand;
protected int size;
Card temp;
/*------------------------------------------
* constructor
* creates arraylist of cards to keep in hand
------------------------------------------*/
public Hand()
{
hand = new ArrayList<Card>();
}
/*-------------------------------
* sets the size of the max hand
------------------------------*/
public void setSize(int newSize)
{
size = newSize;
}
Edit: the error is:
Exception in thread “main” java.lang.StackOverflowError
at Player.<init>(Player.java:19)
at Hand.<init>(Hand.java:21)
line 19 in Player is the “public Player()”
line 21 of Hand is the “public Hand()”
just for reference
HandextendsPlayerand therefore has all ofPlayer‘s data members, includingTo initialize those inherited members,
Hand‘s constructor implicitly callsPlayer‘s.Hand‘s constructor.Player‘s constructor.Player‘s constructor executesnew Hand(), and the cycle repeats indefinitely until you run out of stack space.