Heritage, dynamic binding, counstructor in superclass. Java.
<p>How come the first System.out.println does not print a value of 10? It prints a 0. First a new Child-object is created which calls the constructor in Parent. The constructor in Parent calls lookup in Child because of dynamic binding. So why does lookup in Child return a zero and not a ten?</p>

<pre><code>public class Main332 {
    public static void main(String args[]) {

        Child child = new Child(); 
        System.out.println("child.value() returns " + child.value());//Prints 0

        Parent parent = new Child();
        System.out.println("parent.value() returns " + parent.value());//Prints 0

        Parent parent2 = new Parent();
        System.out.println("parent2.value() returns " + parent2.value());//Prints 5
    }
}


public class Child extends Parent { 
    private int num = 10; 

    public int lookup() {
        return num;
    }
}


public class Parent {
    private int val;

    public Parent() {
        val = lookup();
    }

    public int value() {
        return val;
    }

    public int lookup() {
        return 5;// Silly
    } 
}
</code></pre>
