title: Problem in instance variable initialization
body: <p>Heres some sample code, </p>
  
  <pre><code>class Base
  {
    private int val;
  
    Base() {
    val = lookup();
    }
  
    public int lookup() {
      //Perform some lookup
    // int num = someLookup();
    return 5;
    }
  
    public int value() {
    return val;
    }
  }
  
  class Derived extends Base
  {
    private int num = 10;
  
    public int lookup() {
    return num;
    }
  }
  </code></pre>
  
  <p><br></p>
  
  <pre><code>class Test
  {
    public static void main(String args[]) {
  
    Derived d = new Derived();
    System.out.println("d.value() returns " + d.value());
  
    }
  }
  </code></pre>
  
  <blockquote>
    <p>output: d.value() returns 0            // I expected 10 as lookup() is overridden, but not 0! can someone clarify this?</p>
  </blockquote>
  
  <p>The initialization of <code>Derived</code>'s instance variables has not happened at the time its lookup method executes. How do I make sure the instance variables of <code>Derived</code> are initialized when its method is called? </p>