I want to ask why java initializes the static objects before the non-static objects ?
in this example b3 will be initialized after b4 and b5 :
class Cupboard {
Bowl b3 = new Bowl(3);
static Bowl b4 = new Bowl(4);
Cupboard() {}
static Bowl b5 = new Bowl(5);
}
Because static members of a class are created and initialized (during class loading) before any instance of the class is ever created – they can be accessed without creating an instance of the class as well. Non-static members are created per-instance and thus wait until an instance is created to be initialized for that instance.