title: Java inheritance with threads confusion
body: <p>I am examining code here which uses inheritance and threads. </p>
  
  <p>There is a BaseCom and ServerCom class as below. The ServerCom class extends the BaseCom class. The BaseCom class implements an interface called Com.</p>
  
  <pre><code>public class BaseCom implements Com
  {
     protected final Thread thread;
     protected final InetSocketAddress socketAddress;
  
  
     public BaseCom(InetSocketAddress socketAddress)
     {
        System.out.println("BaseCom CONSTRUCTOR!!!!");
        this.socketAddress = socketAddress;
        thread = new Thread(() -&gt; run(socketAddress));
     }
  
     @Override
     public void start()
     {
        System.out.println("HELLO FROM BaseCom start method!!!!");
        thread.start();
     }
  
     protected void run(InetSocketAddress socketAddress)
     {
        System.out.println("HELLO FROM BaseCom run!!!!");
     }
  
     //.... more stuff .... not shown here 
  }
  </code></pre>
  
  <p>lll</p>
  
  <pre><code>public class ServerCom extends BaseCom
  {
  
     public ServerCom(InetSocketAddress socketAddress, long timeOutMs)
     {
        super(socketAddress);
        System.out.println("ServerCom CONSTRUCTOR!!!!");
  
     }
  
     @Override
     protected void run(InetSocketAddress socketAddress)
     {
        System.out.println("ServerCom run method!!!!");
     }
     // ... more stuff.. not shown here
  }
  </code></pre>
  
  <p>Why is it when I run the following code below from a main function, that actually the run method of the ServerCom class gets executed and not that of the basecom class? </p>
  
  <p>The fact that line <code>thread = new Thread(() -&gt; run(socketAddress));</code> is inside the BaseCom class and not the ServerCom class, would make me think that it should be the Basecom run method which gets called.</p>
  
  <pre><code>connectorA = new ServerCom(socketAddressA, 1000000);
  connectorA.start();
  </code></pre>