java静态方法和静态块有区别,非法转发引用原因 [英] java static method and static block having difference illegle forward referce why

查看:84
本文介绍了java静态方法和静态块有区别,非法转发引用原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class A
        {
       static {
            System.out.println(y);
          }
       static int y=10;
    }



上面的代码产生错误。

但是下面的代码不会产生错误为什么




the above code produce error.
But the below code does not produce error why

class A
{
      static int i=m1();
      static int m1()
       {
            System.out.println(y);
                 return 10;
       }
      static int y=10;
}

推荐答案

参见http://www.jusfortechies.com/java/core-java/static-blocks.php [ ^ ]。你可以轻易找到的东西。
See http://www.jusfortechies.com/java/core-java/static-blocks.php[^]. Something you could easily have found for yourself.


这篇关于java静态方法和静态块有区别,非法转发引用原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆