learningUser learningUser - 2 years ago 72
Java Question

How to access local variables of inner class

I have a class with a inner class of type array. I want to get access to the local variable in the inner class outside the outer class.

public class Fruits {

public Citrus citrus[];
}
public class Citrus{

public String lemon;
public String orange;
}


Now I want to get the variable
lemon
from inner class outside of these classes.
I get the error class cannot be resolved to type

Answer Source

i find a way for u. when u use array, u should use index for access each item of array.

public class Fruits {

    public Citrus citrus[];

    public void  test() {
        String temp=citrus[0].lemon;
    }

}
 class Citrus {
    public String lemon;
    public String orange;
}

now in u can get lemons and oranges from array.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download