Reputation:
class MyThread extends Thread{ //
public void run(){
Thread t1=Thread.currentThread();
System.out.println(t1.getName());
}
}
class Demo{
public static void main(String args[]){
Thread t1=new MyThread();
t1.setName("MyThread");
t1.run();
t1.start();
}
}
It prints "main" when it calls run().Why it is not the "MyThread"
Upvotes: 0
Views: 43
Reputation: 695
It is not the MyThread
class because run()
method is just call, it is still running in the context of the main thread.
A thread itself does not turn into a new thread until call to start()
which happens after the call to run()
.
Upvotes: 2