You have a static and an instance initializer in this code block.
In sequence, the static initializers are run first, then the instance initializers when an instance of the object is created. This is specified by JLS 12.4.2 and JLS 12.5:
- Next, execute either the class variable initializers and static initializers of the class, or the field initializers of the interface, in textual order, as though they were a single block.
A new class instance is explicitly created when evaluation of a class instance creation expression (§15.9) causes a class to be instantiated.
... 4. Execute the instance initializers and instance variable initializers for this class, assigning the values of instance variable initializers to the corresponding instance variables, in the left-to-right order in which they appear textually in the source code for the class. If execution of any of these initializers results in an exception, then no further initializers are processed and this procedure completes abruptly with that same exception. Otherwise, continue with step 5.
To break it down a bit more:
- By virtue of the class being loaded,
"x"
is printed first.
- By initializing an instance of
Sequence
, "y"
is printed next.
- By calling the no-arg constructor of
Sequence
, "c"
is printed third.
- By invoking the
go
method, "g"
is printed last.