How to determine the initialization order of object properties depending on different situations and context?

The question is quite simple, as can seem to much.

In General:
abstract class A {
 int a = 8;

 public A() {

 abstract void show();

class B extends A {
 int a = 90;

 void show() {
 System.out.println("" + a);


And in the main method create an object of class B:
public static void main(String args[]) { 
 new B(); // output - 0

It is understandable, the superclass constructor will cause a polymorphic version of the show (especially in the base class it is abstract). The context variable is a change (one that is in the class B was not yet initialized to a value of 90, because it happens in the constructor?). But first, when you create an object B needs to be initialized its parent, all the fields that are there. When, then, the JVM has time to initialize the field to a zero when the command first calls the superclass constructor?

And that's all, if you slightly change the code in class B:
class B extends A {
 int x = 90; // changed the variable name!

 void show() {
 System.out.println("" + a); // 8

The printed value of the variable a from the context object A - 8. Then I can still somehow understand that you initialize a variable before the call f-tsii show. Like that:
public A() {
 super(); // constructor Call Object and
 a = 8;

But when the time to initialize the field a in the context of object B, if at all, first the JVM is running on its base class? In General there are there subtleties?
June 8th 19 at 16:48
1 answer
June 8th 19 at 16:50
the variable int to initialize has a value of 0;

Static fields of the Parent class;
Static initialization block Parent class;
Static class fields Сhild;
A static initialization block class Child;
Nonstatic fields of the Parent class;
Non-static initialization block Parent class;
The constructor of the Parent class;
Non-static class fields Сhild;
Non-static initialization block class Сhild;
The class constructor Сhild.

I.e. in the first version you can print out the value of an uninitialized class variable B, and the second already initializewindow variable from A.
Ie the non-static fields are initialized before the constructor fires? - Fern.Pacoch commented on June 8th 19 at 16:53

Find more questions by tags Java