该public abstract method
会是在为其他包访问protected abstract method
不能被访问.请查看以下示例.
具有公共和受保护抽象方法的抽象类
package package1; public abstract class MyClass { abstract protected String method1(); abstract public String method2(); }
另一个扩展类并实现抽象类的包.
package package2; import package1.MyClass; public class MyClassImpl extends MyClass { @Override protected String method1() { return "protected method"; } @Override public String method2() { return "public method"; } }
用于访问抽象方法的主类.
package package2; import package1.MyClass; public class MainClass { static MyClass myClass = new MyClassImpl(); public static void main(String[] args) { System.out.println(myClass.method1()); // This is compilation error. System.out.println(myClass.method2()); } }