You are here: Home / Topics / Java Program to explain Main thread and currentThread( ) method

Java Program to explain Main thread and currentThread( ) method

Filed under: Java on 2023-09-22 06:46:01

// Program Main thread and currentThread( ) method

class CurrentThread
{
public static void main( String args[ ] )
{
 Thread t = Thread.currentThread();
 System.out.println( "Current Thread is = " + t );

 t.setName( "My Thread" );
 System.out.println( "After Changing Name is = " + t );
}
}


Output:

Current Thread is = Thread[main,5,main]
After Changing Name is = Thread[My Thread,5,main]

About Author:
G
Geetam     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.