I have made an Outer and an Inner class. Both these classes have variable int x
. How to access x
of Outer class in inner class. this.x
is not working.
class OuterClass {
int x,y;
private class InnerClass {
private void printSum(int x,int y) {
this.x=x;
this.y=y;
}
}
}
You can try this :
private void printSum(int x,int y) {
OuterClass.this.x=x;
OuterClass.this.y=y;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With