我有两个具体的类和一个抽象的超类。抽象超类有一个名为play()的抽象方法,它接受两个参数并返回一个类型字符串。在robot类上实现play()方法时,我不想使用默认的方法签名,因此我重载了它。但是如何隐藏重写的方法呢?有什么好的设计实践吗?
abstract class Player {
public abstract String play(String gesture, Robot p2);
}
class Human extends Player {
@Override
public String play(String gesture, Robot p2) {
//code here
return "player code";
}
}
class Robot extends Player {
@Override
public String play(String gesture, Robot p2) {
//I don't want to use this method but I need to implement this
return null;
}
public String play() {
//this is the method that I want to use
return "robot code";
}
}
暂无答案!
目前还没有任何答案,快来回答吧!