Hello Bin,
Only answers 2 and 4 are correct.
I have written a code to demonstrate this:
public class Wrap
{
public static void main(
String[] args)
{
th t = new th();
Thread tt = new Thread(t);
tt.start();
Thread tt1 = new Thread(t);
tt1.start();
}
}
class th implements Runnable
{
int i = 0;
public void run()
{
i++;
if(i==1)
loop();
else
loop1();
}
public void loop()
{
for(int i=0;i<500;i++)<br /> {<br /> if(i==150)<br /> //throw new NumberFormatException();<br /> System.exit(0);<br /> System.out.println(i);<br /> }<br /> <br /> }<br /> <br /> public void loop1()<br /> {<br /> System.out.println("In the second loop");<br /> <br /> for(int i=500;i>0;i--)
System.out.println(i);
}
}
About 4 :As shown in the code,when you call System.exit(0) in any thread,the JVM exits (Check the output stops there).
About 5 & 6 : They are not correct,if an uncaught exception arises in any thread then only that thread throws the exceotion and stops processing but other thread are still working(To check this,in above code,comment the System.exit(0) line and uncomment the originally commented line).You will see an exception is raised and that thread stops processing but other thread still shows output.
Hope you are clear.
Regards,
Hemant