这是因为子类有知名度
private的
void func()方法,但是超有知名度
public。
如果您的代码被允许编译,那么您将在运行时爆炸:
parent p = new TestClass();p.func(); // boom - func is public in parent, but TestClass's impl is private, so no access would be allowed
要“修复”此问题,请使用子类的
func方法
public:
public class TestClass extends parent { ... public void func() { // give it public visibility System.out.println("in child"); }}并且请使用标准的命名约定;在这种情况下, “课程应以大写字母开头” -即
Parent不是
parent



