Difference between initializing a class and instantiating an object?

后端 未结 4 1682
鱼传尺愫
鱼传尺愫 2020-11-29 05:46

I tried searching for this question through the search engine but could find a topic that explained the difference between initializing a class and instantiating an object.<

4条回答
  •  野性不改
    2020-11-29 06:02

    Initializing a class is done using a static initialization block. (static { }). It's not a method, it's an initializer. It is executed the first time the class itself is referenced.

    Instantiating an object is done for example with new keyword by calling its constructor. At that time static initialization block will not be executed.

提交回复
热议问题