当前位置: 技术问答>java相关
scjp的一道题
来源: 互联网 发布时间:2015-02-27
本文导语: 6. 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); } } what you have to do to ensure that 'j' will print ...
6. 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);
}
}
what you have to do to ensure that 'j' will print 100
you have make t1 as Daemon Thread
You have join the t1 to main
You have to suspend the main when the thread starts and resume it after
the value of 'j' is set to 100
You have to interrupt the main thread
Ans:B
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);
}
}
what you have to do to ensure that 'j' will print 100
you have make t1 as Daemon Thread
You have join the t1 to main
You have to suspend the main when the thread starts and resume it after
the value of 'j' is set to 100
You have to interrupt the main thread
Ans:B
|
1.you have make t1 as Daemon Thread
u not make it...for after u have run it ..if it is finished .it will seem to be dead
2. You have join the t1 to main
u not write it ..the run() will never to run
3.You have to suspend the main when the thread starts and resume it after
the value of 'j' is set to 100
if u not do it,and just do
public void run() {
j=100;
}
it will OK
4.You have to interrupt the main thread
????it is fun
u not make it...for after u have run it ..if it is finished .it will seem to be dead
2. You have join the t1 to main
u not write it ..the run() will never to run
3.You have to suspend the main when the thread starts and resume it after
the value of 'j' is set to 100
if u not do it,and just do
public void run() {
j=100;
}
it will OK
4.You have to interrupt the main thread
????it is fun
|
问题的选项好象有问题?
|
看不懂问题和答案???