Getting error “The inherited method in Abs.show() cannot hide the public abstract method in iface”
获取以下所写代码的错误"abs.show()中的继承方法无法隐藏iface中的公共抽象方法"。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | package com.xprodev; abstract class Abs { void show(){ System.out.println("in show"); } abstract public void print(); } interface iface { void show(); void print(); } public class BasicAbs extends Abs implements iface { public static void main(String[] args){ BasicAbs a = new BasicAbs(); a.show(); a.print(); } @Override public void print() { System.out.println("in print"); } } |
我可以通过在abs中公开展示来解决这个错误。但我没什么问题
Why the language support for this usage?
不是的-这就是你出错的原因
What can be achieved if this is allowed?
回想一下,
on calling a.print() only implementation of print will be called . Is
that make sense to call this implementation is of method in Abs class
or iface interface. Can we know that?
收益率:
1 | class BasicAbs |