【发布时间】:2014-04-21 01:49:11
【问题描述】:
我有两个类,在Player 类中,我有定义为private int collectedDots 的变量,我想在另一个类Exit 中访问。
我已经在 Player 类中定义了 Get 和 Set 方法:
public void setCollectedDots(int cd)
{
collectedDots = cd;
}
public int getCollectedDots()
{
return collectedDots;
}
但现在我想从Exit 类访问collectedDots 字段。当我将这两种方法复制到 Exit 类中时,我不断收到错误cannot find symbol - variable collectedDots。
我的理解是,一旦我设置了 get 和 set 方法,我就可以从 Player 类中检索 collectedDots 变量..
任何想法我要去哪里错了吗?
【问题讨论】:
-
您需要在退出时调用播放器上的方法,而不是复制它们。
-
@Pietu1998:你可能应该这样回答
-
@Pietu1998 我试过这样做,我有一个 if 语句读取 if (Player.getCollectedDots