Java static block静态快

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.

 

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

你可能感兴趣的:(java,UP)