Java客户端错误

时间:2015-04-02 01:02:47

标签: java

我一直在学习继承并且正在处理一个项目,该项目涉及父母类运动员和儿童类HockeyPlayer。当我编译时,它说我在客户端调用setGoals时找不到符号:

    Athlete hockey = new HockeyPlayer();
    hockey.setGoals(10);

以下是HockeyPlayer类的代码:

public class HockeyPlayer extends Athlete
{
    private int goals, number;
    private String team;

    public HockeyPlayer()
    {
        super();  //sets name, age, and salary from Athlete constructor
        goals = 0;
        number = 0;
        team = "";
    }

    public void setGoals(int goals)
    {
        this.goals = goals;
    } 
}

有关如何修复此错误的任何输入?

1 个答案:

答案 0 :(得分:0)

曲棍球运动员不是曲棍球运动员。除非将其投射到曲棍球运动员,否则您只能调用为运动员定义的方法。