JAVA constructor code block, java constructor code
Class G {G () {System. out. println ("I Am a construction method without Parameters");} G (String name) {System. out. println ("I have a constructor, and my parameter value is:" + name) ;}{ System. out. println ("I am constructing a code block");}/* features of constructing a code block: the object runs as soon as it is created, and takes precedence over the constructor: differences between the Construction Code block for object initialization and the construction method: 1. the constructor initializes the corresponding object. 2. The constructor code block initializes all objects in a unified manner. The constructor code block defines the initialization content that is common to different objects. */public class Index {public static void main (String [] args) {G g1 = new G (); G g2 = new G ("James ");}}