B 类中的 show() 方法是“重写”、“实现”还是只是“定义”?
interface A
{
void show();
}
class B implements A
{
public void show()
{
System.out.println("What is the proper term to explain?");
}
}
最佳答案
简短的回答,我们覆盖
这些方法,为什么?
因为这代表了多态语句的概念,请记住
List<String> aa = new ArrayList<>();
// List => interface
// ArrayList => class
aa.add("polymorphic statment");
多态语句和重写是齐头并进的。
尽管任何类都可以选择通过声明自身抽象
来实现接口(interface),并且无需覆盖
任何方法。
注意:在任何 IDE 中应用相同的概念,将指导您添加 @Override
注解。
关于java - 当我们在类中定义接口(interface)的抽象方法时,我们是 'override' 还是 'implement' 或者简单地说 'define' 这些方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51225774/