Jump to content

Question about java thread


Recommended Posts

Hello,

https://www.w3schools.com/java/java_threads.asp

 

 public class Main extends Thread {
  public static void main(String[] args) {
    Main thread = new Main();
    thread.start();
    System.out.println("This code is outside of the thread");
  }
  public void run() {
    System.out.println("This code is running in a thread");
  }
}

I am not able to understand two

System.out.println("This code is outside of the thread");
System.out.println("This code is running in a thread");

messages. How does one  is running outside of the thread and another is running in a thread? If you clarify a bit more(with an example) what is running in a thread and what is running outside of a thread.

Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...