I am new in java. Can someone help me why it is not calling Run method.
Thanks in advance.
package com.blt;
public class ThreadExample implements Runnable {
public static void main(String args[])
{
System.out.println("A");
Thread T=new Thread();
System.out.println("B");
T.setName("Hello");
System.out.println("C");
T.start();
System.out.println("D");
}
public void run()
{
System.out.println("Inside run");
}
}
You need to pass an instance of
ThreadExampleto theThreadconstructor, to tell the new thread what to run:(It’s unfortunate that the
Threadclass has been poorly designed in various ways. It would be more helpful if it didn’t have arun()method itself, but did force you to pass aRunnableinto the constructor. Then you’d have found the problem at compile-time.)