当我们在子类中重写父类的方法的时候,子类的权限不能低于父类的权限。
比如:
class A
{
access_specifier_1 void f()
{
System.out.printf (“AAAA\n”);
}
}
class B extends A
{
access_specifier_2 void f()
{
System.out.printf (“BBBB\n”);
}
}
access_specifier_1 | access_specifier_2 | Result |
public | public | OK |
protected | public | OK |
default | protected | OK |
private | private | OK |
public | protected | Error |
default | protected | Error |
private | public | Error |