I am trying to understand this example from "Thinking in Java" :
package c07; import com.bruceeckel.simpletest.*; class Meal { Meal() { System.out.println("Meal()"); } } class Bread { Bread() { System.out.println("Bread()"); } } class Cheese { Cheese() { System.out.println("Cheese()"); } } class Lettuce { Lettuce() { System.out.println("Lettuce()"); } } class Lunch extends Meal { Lunch() { System.out.println("Lunch()"); } } class PortableLunch extends Lunch { PortableLunch() { System.out.println("PortableLunch()");} } public class Sandwich extends PortableLunch { private static Test monitor = new Test(); private Bread b = new Bread(); private Cheese c = new Cheese(); private Lettuce l = new Lettuce(); public Sandwich() { System.out.println("Sandwich()"); } public static void main(String[] args) { new Sandwich(); monitor.expect(new String[] { "Meal()", "Lunch()", "PortableLunch()", "Bread()", "Cheese()", "Lettuce()", "Sandwich()" }); } }
As I understand from the specification of the Java language, the execution order begins with loading the class containing the main method. Then all statistical and member variables of this class should be initialized (before which all member variables of the superclasses should be informed, although in this case there is none of them).
So, I thought b , c , l would be initialized before main started. However, this is not so. Did I miss something?
source share