K
KittyCreation
The following code produces this output always :
A.The number 14 is printed before number 22
B.The last number printed is 12.
Please can someone explain me the output of the following code.
Please explain how the code works to ensure the output behaviour...
I 've tried hours to understand it but I cannot.
//==============CODE
public class cc{
ArrayList arl = new ArrayList();
boolean flag = false;
static Thread create(final int i, final Thread t1)
{ Thread t2 = new Thread(){
public void run(){
System.out.println(i+1);
try
{
t1.join();
}
catch(InterruptedException e){}
System.out.println(i+2);
}
};
System.out.println(i+3);
t2.start();
System.out.println(i+4);
return t2;
}
public static void main(String [] args)
{
create(10,create(20,Thread.currentThread
())); }}
A.The number 14 is printed before number 22
B.The last number printed is 12.
Please can someone explain me the output of the following code.
Please explain how the code works to ensure the output behaviour...
I 've tried hours to understand it but I cannot.
//==============CODE
public class cc{
ArrayList arl = new ArrayList();
boolean flag = false;
static Thread create(final int i, final Thread t1)
{ Thread t2 = new Thread(){
public void run(){
System.out.println(i+1);
try
{
t1.join();
}
catch(InterruptedException e){}
System.out.println(i+2);
}
};
System.out.println(i+3);
t2.start();
System.out.println(i+4);
return t2;
}
public static void main(String [] args)
{
create(10,create(20,Thread.currentThread
())); }}