You need to sign in to do that
Don't have an account?

Can't Inner class access the variable of Outer class?
I am getting an error for the below code
Public Class MyOuter
{
Interger i = 10; // Variable of Outerclass
Public Class MyInner
{
//Here I am accessing outer class variable
i = 1+10; // Here I am getting an error message as
}
}
Can't Inner class access the variable of Outer class?
Thanks
No, as the inner class doesn't know anything about the instance of the outer class that you'd like to associate it with. You can access static variables, but not instance variables.
If you need this, you need to pass a reference to the MyOuter instance to the constructor of MyInner.