What is the proper way of accessing static fields in Java?

后端 未结 6 1490
面向向阳花
面向向阳花 2020-12-04 00:24

I just started learning Java and I wrote a class to test using static fields. Everything works fine but in Eclipse I see an icon which when hovered comes out as: \"The stati

6条回答
  •  情书的邮戳
    2020-12-04 00:43

    It is even possible, though highly discouraged, to write:

    Math m = null;
    double d = m.sin(m.PI/4.0);
    System.out.println("This should be close to 0.5 " + (d*d));
    

    This is because static accesses look at the declared type of the variable, and never actually dereference it.

提交回复
热议问题