Consider the following code
class OuterClass{
class InnerClass{
int x;
int y;
void calculateX(){
x = y+z;//I want to acce
You can try using getter method for y
class OuterClass{
class InnerClass{
int x;
int y;
void calculateX(){
x = getY() + x;
}
void printX(){
print();
}
}
int y;
int z;
InnerClass instance;
OuterClass(int y,int z){
this.y = y;
this.z = z;
instance = new InnerClass();
instance.y = 10;
instance.calculateX();
instance.printX();
}
void print(){
System.out.println("X:"+instance.x+"\nY:"+y+"\nZ:"+z+"\n");
}
public int getY() {
return y;
}
}