输出字符的总数可能改变。
当添加额外的代码时,编译将失败。
在“after”输出结果中,字符“m”较早出现的可能性较小。
在“after”输出结果中,字符“m”较早出现的可能性较大。
第1题:
interface A{
int x = 0;
}
class B{
int x =1;
}
class C extends B implements A {
public void pX(){
System.out.println(x);
}
public static void main(String[] args) {
new C().pX();
}
}
错误。在编译时会发生错误(错误描述不同的JVM 有不同的信息,意思就是未明确的
x 调用,两个x 都匹配(就象在同时import java.util 和java.sql 两个包时直接声明Date 一样)。
对于父类的变量,可以用super.x 来明确,而接口的属性默认隐含为 public static final.所以可
以通过A.x 来明确。
第2题:
public class Threads3 implements Runnable { public void run() { System.out.print(”running”); } public static void main(String[] args) { Thread t = new Thread(new Threads3()); t.run(); t.run(); t.start(); } } What is the result?()
第3题:
public class Threads5 { public static void main (String[] args) { new Thread(new Runnable() { public void run() { System.out.print(”bar”); } }).start(); } } What is the result?()
第4题:
class Order3 implements Runnable { public static void main(String [] args) { new Thread(new Order3()).start(); for(int x = 0; x 〈 10; x++) System.out.print("m"); } public void run() { for(int x = 0; x 〈 10; x++) { //insert code here System.out.print("r"); } } } 和: 当代码被编译并照此运行时产生 "before" 的输出, 当下列内容插入到代码第8行时产生"after"输出 if (x 〉 3 && x 〈 7) Thread.yield(); 对比“before”的输出结果和“after”的输出结果,下面哪一项是正确的?()
第5题:
public class TestOne implements Runnable { public static void main (String[] args) throws Exception { Thread t = new Thread(new TestOne()); t.start(); System.out.print(”Started”); t.join(); System.out.print(”Complete”); } public void run() { for (int i= 0; i< 4; i++) { System.out.print(i); } } } What can be a result?()
第6题:
5. class Order2 implements Runnable { 6. public void run() { 7. for(int x = 0; x 〈 4; x++) { 8. try { Thread.sleep(100); } catch (Exception e) { } 9. System.out.print("r"); 10. } } 11. public static void main(String [] args) { 12. Thread t = new Thread(new Order2()); 13. t.start(); 14. for(int x = 0; x 〈 4; x++) { 15. // insert code here 16. System.out.print("m"); 17. } } } 哪一个插入到第15行,最有可能产生输出 rmrmrmrm ?()
第7题:
现有: 5. class Order2 implements Runnable { 6. public void run() { 7. for (int x- o; x<4; x++) { 8. try{Thread.sleep(100); )catch (Exception e) { } 9. System.out.print("r"); 10. } } 11. public static void main(string [] args) { 12. Thread t=new Thread(new order2()); 13. t.start(); 14. for(int x=0; x<4; x++) { 15. //insert code here 16. System.out.print("m"); 17. } } } 哪一个插入到第15行,最有可能产生输出 rmrmrmrm?()
第8题:
Compilation fails.
An exception is thrown at runtime.
The code executes and prints “running”.
The code executes and prints “runningrunning”.
The code executes and prints “runningrunningrunning”.
第9题:
main
编译失败
main java.lang.RuntimeException: exception
代码运行,但没有输出
第10题:
0
1
2
3
第11题:
0, 2, 4, 4, 6, 8, 10, 6,
0, 2, 4, 6, 8, 10, 2, 4,
0, 2, 4, 6, 8, 10, 12, 14,
0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14,
0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,
第12题:
Thread.sleep(1);
Thread.sleep(100);
Thread.sleep(1000);
try { Thread.sleep(100); } catch (Exception e) { }
第13题:
( 30 )在程序的下划线处应填入的选项是
public class Test _________{
public static void main(String args[]){
Test t = new Test();
Thread tt = new Thread(t);
tt.start();
}
public void run(){
for(int i=0;i<5;i++){
system.out.println( " i= " +i);
}
}
}
A ) implements Runnable
B ) extends Thread
C ) implements Thread
D ) extends Runnable
第14题:
现有: class Passer f static final int X=5; public static void main (String [] args) { new Passer().go (x); System. out .print (x); } void go (int x) { System. out .print(x++); } 结果是什么?()
第15题:
现有: class ThreadExcept implements Runnable { public void run() { throw new RuntimeException("exception "); } public static void main(Stri_ng [] args) { new Thread (new ThreadExcept()).start(); try { int x=Integer.parselnt (args [0]); Thread. sleep (x); System.out.print("main"); } catch (Exception e) { } } } 和命令行: java ThreadExcept l000 哪一个是结果?()
第16题:
class ThreadExcept implements Runnable { public void run() { throw new RuntimeException("exception "); } public static void main(String [] args) { new Thread(new ThreadExcept()).start(); try { int x = Integer.parseInt(args[0]); Thread.sleep(x); System.out.print("main "); } catch (Exception e) { } } } 和命令行: java ThreadExcept 1000 哪一个是结果?()
第17题:
public class Threads 1 { intx=0; public class Runner implements Runnable { public void run() { int current = 0; for(int=i=0;i<4;i++){ current = x; System.out.print(current + “, “); x = current + 2; } } } public static void main(String[] args) { new Threads1().go(); } public void go() { Runnable r1 = new Runner(); new Thread(r1).start(); new Thread(r1 ).start(); } } Which two are possible results?()
第18题:
1. class MyThread implements Runnable { 2. public void run() { 3. System.out.print("go "); 4. } 5. 6. public static void main(String [] args) { 7. // insert code here 8. t.start(); 9. } 10. } 和如下四句: Thread t = new MyThread(); MyThread t = new MyThread(); Thread t = new Thread(new Thread()); Thread t = new Thread(new MyThread()); 分别插入到第5行,有几个可以通过编译?()
第19题:
public class Threads4 { public static void main (String[] args) { new Threads4().go(); } public void go() { Runnable r = new Runnable() { public void run() { System.out.print(”foo”); } }; Thread t = new Thread(r); t.start(); t.start(); } } What is the result?()
第20题:
输出字符的总数可能改变。
当添加额外的代码时,编译将失败。
在“after”输出结果中,字符“m”较早出现的可能性较小。
在“after”输出结果中,字符“m”较早出现的可能性较大。
第21题:
Compilation fails.
An exception is thrown at runtime.
The code executes and prints “StartedComplete”.
The code executes and prints “StartedComplete0123”.
The code executes and prints “Started0l23Complete”.
第22题:
55
56
65
66
第23题:
Thread.sleep(1);
Thread.sleep(100);
Thread.sleep(1000);
try{ Thread.sleep(1); ) catch (Exception e) { }
try{Thread.sleep(100); ) catch (Exception e) { }
try{Thread.sleep(1000); ) catch (Exception e) { }
第24题:
main
编译失败
代码运行,但没有输出
main java.lang.RuntimeException: exception