Thread class does not contain constructor which takes Object class as parameter

by Mukul Goyal   Last Updated June 13, 2019 08:26 AM

The Thread class does not contain constructor which takes Object type as parameter so how it calls the constructor during multi-threading. Below is the code in which i need explanation.

Thread t = new Thread(myThread); //How this line execute.

    class MyThread implements Runnable  
    {  
     @Override  
    public void run()
    {   

        for(int i = 0; i < 1000; i++)
        {
            System.out.println(i+" * "+(i+1)+" = " + i * (i+1));
        }
    }
     }

    public class ThreadsInJava
    {
      //Main Thread
     public static void main(String[] args)
    {
        MyThread myThread = new MyThread();  

        Thread t = new Thread(myThread);     

        t.start();                          
    }
Tags : java


Answers 1


The Thread class takes an Runnable as parameter. So your class implements the Runnable it can be given to the constructor because the class is a Runnable after implementing it.

CodeMatrix
CodeMatrix
June 13, 2019 08:25 AM

Related Questions


Updated January 09, 2018 04:26 AM

Updated November 04, 2017 02:26 AM

Updated November 17, 2018 17:26 PM