title: How a run() method is called when we extend Thread class
body: <p>While going through the source code of <code>java.lang.Thread</code> class. Curiously I wanted to see how a <code>run()</code> method (user defined run()) is called by Thread class. when I am implementing <code>Runnable</code> interface as below</p>
  
  <pre><code>Thread waiterThread = new Thread(waiter, "waiterThread");
  waiterThread.start();
  </code></pre>
  
  <p>In the above code from <code>Thread</code> class's constructor <code>init()</code> method is being called and from there itself they initialized the <code>Runnable</code> instance as <code>this.target = target</code>.</p>
  
  <p>from <code>start()</code> method they are calling a <code>native</code> method <code>start0()</code> which may in-turn call <code>run()</code> method of the <code>Thread</code> class which causes user defined <code>run()</code> method to execute.</p>
  
  <p>the following is the <code>run()</code> method implementation from Thread class:</p>
  
  <pre><code> @Override
  public void run() {
      if (target != null) {
          target.run();
      }
  }
  </code></pre>
  
  <p>My question is when we extend <code>java.lang.Thread</code> class and when we call <code>start()</code> method as below.</p>
  
  <pre><code>public class HelloThread extends Thread {
  
    public void run() {
      System.out.println("Hello from a thread!");
    }
  
    public static void main(String args[]) {
        (new HelloThread()).start();
     }
  
   }
  </code></pre>
  
  <p><code>target = null</code> in the above case so is it the native method's (<code>start0()</code>) responsibility to set target=HelloThread's instance ? and how does a <code>run()</code> method of mine is called in case when I extend <code>Thread</code> class?</p>