そのため、私の小さなJavaプログラムでは、mainメソッドですべての変数を宣言しましたが、クラス内のどこからでも変数を変更できるようにしたかったので、代わりにクラス本体で宣言しました。これで、mainメソッド内でそれらを変更することができなくなりました。変数を静的に宣言するための解決策はありますか?そうする場合でも、mainメソッド内からこれらの変数を変更できますか?
public class MainGUI
{
int num1= 1366, num2= 528, num3= 482, sum; // declare these static?
public static void main(String args[])
{
sum = num1 + num2+ num3; //compiler tells me "non-static varable cannot be refrenced from a static context"
}
}