The Java code demonstrates how to create a thread by implementing the Runnable interface. The CreateThread_Implementing class implements the Runnable interface, and its run() method defines the behavior of the thread. Here's a step-by-step explanation of what happens when you run this code:
Since the thread runs concurrently with the main thread, the order of the output is not guaranteed. It may vary based on the thread scheduler and system behavior. However, you will always see both "Thread Executed" and "Outside Thread" printed to the console.
public class CreateThread_Implementing implements Runnable { public static void main(String[] args) { CreateThread_Implementing m = new CreateThread_Implementing(); Thread thrd = new Thread(m); thrd.start(); System.out.println("Outside Thread"); } public void run() { System.out.println("Thread Executed"); } }
Outside Thread Thread Executed
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions