public class Knowing {
static final long tooth = 343L;
static long doIT(long tooth) {
System.out.print(++tooth + " ");
return ++tooth;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print(tooth + " ");
final long tooth = 340L;
new Knowing().doIT(tooth);
System.out.println(tooth);
}
}
さて、ここに私の質問があります:
グローバル変数が宣言されている場合
static final long tooth = 343L;
、メイン メソッドで別の変数を宣言するにはどうすればよいfinal long tooth = 340L;
ですか。実行してエラーがなかったので、なぜこれが許可されているのかを知りたいだけです。また、新しいinstance.variable名を作成するのではなく、 className.variableNameを使用してグローバル静的変数の歯にアクセスするべきではありませんか?警告のみで許可されるのはなぜですか?