2012-05-08 29 views
-4

我收到錯誤「刪除無效修改」當我使用類動物園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()); 
    } 

我該如何解決這個問題?

回答

0

只能公開課程。內部類可以被保護

1

protected改性劑僅在內部或嵌套類有效。

1

頂級(非內部)類不能是protected,只能是public或包(默認)訪問。