What is the difference between a static and a non-static initialization code block

后端 未结 8 1802
萌比男神i
萌比男神i 2020-11-21 23:32

My question is about one particular usage of static keyword. It is possible to use static keyword to cover a code block within a class which does not belong to

8条回答
  •  温柔的废话
    2020-11-22 00:14

    The static code block can be used to instantiate or initialize class variables (as opposed to object variables). So declaring "a" static means that is only one shared by all Test objects, and the static code block initializes "a" only once, when the Test class is first loaded, no matter how many Test objects are created.

提交回复
热议问题