I wanted to print 100 as output in the below program.
I am getting 0 as answer.
class s extends Thread{
int j=0;
public void run() {
try{Thread.sleep(5000);}
catch(Exception e){}
j=100;
}
public static void main(String args[])
{
s t1=new s();
t1.start();
System.out.println(t1.j);
}
}
You have join the t1 to main.
So, the parent
thread(main())will wait till the child thread is complete.