package learning.java.basics1;
class Child implements Runnable{
Child(){
Thread t = new Thread(this);
t.setName("SH");
t.start();
}
public void run(){
System.out.print("child thread : "+Thread.currentThread().getName());
}
}
public class C2 {
public static void main(String[] args) {
new Child();
System.out.print("Thread name of main :"+Thread.currentThread().getName());
}
}
It prints :
Thread name of main : main
child thread : SH
So with each public class execution (here C2) JVM creates a Thread called "main" (or already existing thread with this name) and its run() method, calls our main method?
So execution step for each Java file that contains main method is as follows:
- JVM creates a thread called main,
- main(thread) calls run method
- run method calls directly its static method main() without creating any object.
Is it true ?