這是你的代碼:
public int foo {
public int valueofX() {
abc a = new abc(); //You create a new 'abc' element and store it in 'a'
return a.getX(); /*Here you access the method 'getX()' from 'a', and 'a'
contains and 'abc' object. It gives you back the value x,
and it's with this method you could modify x.
*/
}
private final class abc {
private int x = 0; // this value is changed later in the code
public int getX() {
return x; //this always give me 0
} /*CORRECTION: This will give you 'X', that initially
has the value of 0 */
}
}
要訪問'a'(abc類)的'x'變量,必須使用返回它的merthod。
如果您只想訪問'x'值,請按照我所寫的內容進行操作。
a.valueOfX(); //This will return X, you can store it, operate with it, use it.
您可以發佈的[MCVE(http://stackoverflow.com/help/mcve),我們可以改爲運行的這個不完整的代碼? –