Input
Output
public class Joinmethod1 { public static void main(String args[]){ Joinmethod t1=new Joinmethod("One"); Joinmethod t2=new Joinmethod("Two"); Joinmethod t3=new Joinmethod("Three"); System.out.println("Thread One is alive: "+ t1.t.isAlive()); System.out.println("Thread Two is alive: "+ t2.t.isAlive()); System.out.println("Thread Three is alive: "+ t3.t.isAlive()); try{ System.out.println("Waiting for threads to finish."); t1.t.join(); t2.t.join(); t3.t.join(); }catch(InterruptedException e){ System.out.println(e); } } } class Joinmethod implements Runnable { String name; // name of thread Thread t; Joinmethod(String threadname) { name = threadname; t = new Thread(this, name); System.out.println("New thread: " + t); t.start(); // Start the thread } public void run(){ try{ for(int i=1;i<=5;i++){ System.out.println(i); Thread.sleep(700); } }catch(InterruptedException e){ System.out.println(e); } System.out.println(name + " exiting."); } }