prr
课程有public abstract prr()
。
根据官方java文档应该不可能写出摘要&私有关键字在一起,但它在Eclipse中编译
abstract class prr {
/* we have an abstract class as prr. There is a method as show.*/
abstract private void show();
}
// Since show() is abstract, this is redefined in App class.
// Ideally show() should not even be seen in App because it is private.
public class App
{
private void show(){
System.out.println("Inside prr");}
public static void main(String args[]) {
App m = new App();
m.show();}}
输出结果为:
内部prr
如何根据docs在eclipse下编译它是不可能的?
答案 0 :(得分:0)
不能从超类继承私有方法。必须在派生类中重写和实现抽象方法。由于私有方法不能被继承,因此声明一个私有的抽象方法是没有意义的。制作抽象方法public
或protected
私有方法对于其定义的类是私有的。
您可以像这样修改代码:
abstract class Prr {
protected abstract void show();
}
public class App extends Prr {
@Override
void show() {
System.out.println("Inside prr");
}
public static void main(String args[]) {
App m = new App();
m.show();
}
}