我收到一个错误:
Exception in thread "main" java.lang.StackOverflowError
at CreateCardDeck.<init>(CreateCardDeck.java:6)
at CardStack.<init>(CardStack.java:7)
at CreateCardDeck.<init>(CreateCardDeck.java:8)
at CardStack.<init>(CardStack.java:7)
at CreateCardDeck.<init>(CreateCardDeck.java:8)
...
...
...
at CardStack.<init>(CardStack.java:7)
at CreateCardDeck.<init>(CreateCardDeck.java:8)
但我不明白为什么会有错误。在我的代码中,我指定了卡片数量等。那么这里有什么问题呢?
public class CreateCardDeck
{
int deckSize = 52;
CardStack cardStack;
CreateCardDeck()
{
cardStack = new CardStack(deckSize); --------------- problem here -----
}
}
和
class CardStack extends CreateCardDeck
{
public CardStack(int s) ------------ problem here --------------
{
maxSize = s;
stackArray = new Card[maxSize];
top = -1;
}
......
}