当我在类 Zoo 上使用 protected
关键字时,我收到错误"删除无效修饰符"。
protected class Zoo {
int x=5;
String coolMethod() {
return "Wow baby";
}
static Test t=new Test();
}
public class Test {
public static void main(String args[]) {
Test zoo=new Test();
//System.out.println(zoo.coolMethod());
//System.out.println(x);
//t.useMyCoolMethod();
//Testing v=new Testing();
//System.out.println(v.getValue());
}
我该如何解决这个问题?
protected
修饰符仅在内部类或嵌套类中有效。
顶级(非内部)类不能protected
,只能public
或包(默认)访问。
类
只能是公共的。可以保护内部类