Vote count:
0
According to the JSL 8.4.8.1
An instance method m1, declared in class C, overrides another instance method m2, declared in class A iff all of the following are true:
C is a subclass of A.
The signature of m1 is a subsignature (§8.4.2) of the signature of m2.
Either:
m2 is public, protected, or declared with default access in the same package as C, or
m1 overrides a method m3 (m3 distinct from m1, m3 distinct from m2), such that m3 overrides m2.
it doesn't contradict to the folowing code:
public class Main{
public void f(){ }
public static class A extends Main{
protected void f(){ }
}
public static void main(String[] args){
}
}
But it's not compiling, although the overriden version of the method f()
has protected access modifier, as said in the second point of the rule I provided. What's wrong?
asked 1 min ago
Overriding and weaking access modifiers
Aucun commentaire:
Enregistrer un commentaire