public enum Parent {
item1(1){
public void testing() {
add();
multiply();
minus(); // error here!!!
}
}, item2(2);
private int i ;
Parent(int i){
this.i = i;
}
public void setI(int i ){
this.i = i;
}
public int getI(){
return i;
}
public void multiply(){
}
protected void add(){
}
private void minus(){
}
}
As you guy can see, they are in the same class, how come minus() cannot be used internally? Usually inner class can access private method/field in the outer class right?
To be able to access
minus()fromitem1, you have to make itprotected(orpublic).The correct way to think about
Parentanditem1is as a base class and a subclass.From the JLS: