title: Instantiating a class from main() vs instantiating from another class
body: <p>I want to instantiate a child class in Java from within a parent class. However, when I do this, and attempt to call a parent's method from the constructor of the child (with super), the returned field is null. If I changed this to instantiating the parent from the main() method, the field returns how it is expected (a String). I'm not sure whats happening here, can anyone explain?</p>
  
  <p>Main class:</p>
  
  <pre><code>public class MainFunc {
  
    public static void main(String[] args) {
      javaClass jv = new javaClass("Bobby");
      jv.makeJ2();
    }
  }
  </code></pre>
  
  <p>Parent Class:</p>
  
  <pre><code>public class javaClass {
  
    String name;
  
    public javaClass(){
    }
  
    public javaClass(String s) {
        setName(s);
    }
  
    public String getName() {
      return name;
    }
    public void setName(String name) {
      this.name = name;
    }
  
    public void makeJ2 (){
      javaClass2 jv2 = new javaClass2();
    }
  }
  </code></pre>
  
  <p>Child Class:</p>
  
  <pre><code>public class javaClass2 extends javaClass {
  
    String name;
  
  
    public javaClass2() {
      super();
      String superTitle = super.getName();
  
      System.out.println("HEY " + superTitle);
    }
  }
  </code></pre>
  
  <p>This returns:</p>
  
  <pre><code>HEY null
  </code></pre>
  
  <p>Instead of:</p>
  
  <pre><code>HEY Bobby
  </code></pre>