在子类中使用超类方法

时间:2014-05-16 01:56:18

标签: java inheritance superclass

我有这个不应该更改的超类,它用于显示每个团队的分数here

public abstract class Playclass {
    private String name;
    Playclass(String name){
        this.name=name;
    }
    public String getName() {
        return name;
    }
    public abstract void print();
    public abstract void won();
    public abstract void drawn();
    public abstract void defeated();

}

我如何在一个例子中使用它?

1 个答案:

答案 0 :(得分:1)

由于Playclass是抽象的,因此无法实例化它。你必须扩展它。这是一个例子:

public class HomeTeam extends Playclass {

    public HomeTeam(String name) {
        super(name);
    }

    @Override
    public void print() {
        //provide your implementation
    }

    @Override
    public void won() {
        //provide your implementation
    }

    @Override
    public void drawn() {
        //provide your implementation
    }

    @Override
    public void defeated() {
        //provide your implementation
    }

    public static void main(String[] args) {
        HomeTeam team = new HomeTeam("Knicks");
    }


}