`
jarod2008
  • 浏览: 80663 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Java static block静态快

    博客分类:
  • java
阅读更多

static variables or static blocks in a class will be initialised before the class gets instantiated. Also, we all know that the static variables are not tied up with the instances. So even if we have the reference as null, the variable s value had already been initalised to "hello". So calling it that way will print the values Inside Method and Hello as the variable call will be made with the class name as they are tied up with the class . If you make the variable non - static , you will get a NPE.

 

静态变量和静态块在类被实例化之前,已经得到初始化。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics