静的変数はクラスの一部であり、オブジェクトの一部ではないことがわかります。どのようにすることができます任意の問題Javaの静的変数
class M
{
static int i=0;
void Inc()
{
System.out.println("Global "+M.i);
System.out.println("Local "+this.i);
}
}
public class StaticTest
{
public static void main(String args[])
{
M m1=new M();
m1.i=99; //How can the m1 object access i variable of the class
m1.Inc();
}
}
私が手出力が
Global 99
Local 99
あるなしにコードの作業の次の行どのようにすることができますクラスのM1オブジェクトアクセス変数i?
すべてのインスタンス変数は、その静的変数を共有します。あなたは間違ってそれを参照しましたが、まだ実行されています –
http://stackoverflow.com/questions/17242649/can-non-static-methods-modify-static-variables –