On page 202 - 203 in the book 'Certified Associate Java SE 8 Programmer I' by Jeanne Boyarsky and Scott Selikoff, there is a code sample that is supposed to give output based on the order of initialization:
Until now, I have never seen print statements like those. We're not in the main method (or any method acually), so how is the the print statement in the block on line 6 supposed to work? And what are those nameless static blocks on lines 10 - 16?
The book says the output is supposed to be:
But the way my code is now, it doesn't print anything. What is going on?
Please be careful about thread names; I have looked for bizarre print statements and didn't find any, and I looked for print statements producing no output, and I didn't find any of them either . I think this is a different version of the same problem you encountered here.
I don't think you will find much about initialisers in the Java™ Tutorials. You can try the Java® Language Specification (=JLS) (also this JLS section), but I would have thought that your book would provide a better description of what initialisers look like.
Nameless initializer blocks allow complex initialization of classes and class instances independent of constructors.
Effectively, nameless static initializers are executed in the order that they appear when the class is first loaded. Nameless non-static initializers are processed similarly except that in effect they are all bundled up into an invisible pre-constructor method that gets invoked before the actual constructors (if any) start processing. Or, if there are no constructors, when an object is instantiated.
Blitzlügen - Lies or information broadcast, but when called out the broadcaster does little or nothing is done to correct them, thus allowing those who wish to believe to accept them as truth.
Lügensturm - A barrage of Blitzlügen fired in such quick succession that it is essentially impossible to correct them all.