日期:2014-05-20 浏览次数:20952 次
package hack;
import click.CodeTalk;
public class TypeIt {
private static class ClickIt extends CodeTalk {
void printMessage() {
System.out.println("Hack");
}
}
public static void main(String[ ] args) {
ClickIt clickit = new ClickIt();
clickit.doIt();
}
}
package click;
public class CodeTalk {
public void doIt() {
printMessage();
}
void printMessage() {
System.out.println("Click");
}
}
# 只截取了doIt方法 public void doIt(); Code: 0: aload_0 1: invokespecial #2; //Method printMessage:()V 4: return LineNumberTable: line 4: 0 line 5: 4
------解决方案--------------------
A package-private method cannot be directly overridden by a method in a different package.
总结就是package-private方法不能直接被另外一个包中的方法覆盖
------解决方案--------------------
8.4.8.1 Overriding (by Instance Methods)
An instance method m1 declared in a 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. (间接覆盖)
Moreover, if m1 is not abstract, then m1 is said to implement any and all declarations of abstract methods that it overrides.