现有: class Waiting implements Runnable { boolean flag=false; public synchronized void run() { if (flag) { flag=false; System.out.print ("1"); try { this.wait(); ) catch (Exception e) { } System.out.print ("2"); } else { flag=true; System.out.print ("3"); try{Thread.sleep (2000); } catch(Exception e) {} System.out.print ("4"); notify(); } } public static void main (String [] args) { Waiting w=new Waiting(); new Thread (w) .start(); new Thread (w) .start(); } } 以下哪两项是正确的?()
A代码输出l 3 4
B代码输出3 4 1
C代码输出l 2 3 4
D代码输出1 3 4 2
E代码运行完毕
F代码不会完成
相关问题推荐
-
在方法的声明中,要求该方法必须抛出异常时使用哪个关键字?()
A、 throw
B、 catch
C、 finally
D、 throws
-
现有: 1. class Alpha { void m1() {} } 2. class Beta extends Alpha { void m2() { } } 3. class Gamma extends Beta { } 4. 5. class GreekTest { 6. public static void main(String [] args) { 7. Alpha [] a = {new Alpha(), new Beta(), new Gamma() }; 8. for(Alpha a2 : a) { 9. a2.m1(); 10. if (a2 instanceof Beta || a2 instanceof Gamma) 11. //insert code here 12. } 13. } 14. } 哪一行代码插入到第11行,将编译但是会在运行时产生异常?()
A、 a2.m2();
B、 ((Beta)a2).m2();
C、 ((Alpha)a2).m2();
D、 ((Gamma)a2).m2();
-
组件的getBounds()方法返回值的类型是哪项?()
A、 Dimension
B、 Rectangle
C、 Point
D、 int[]
-
假设有字符串“123”,能把该字符串变成整数的方法是哪几项?()
A、Integer.parseInt(”123”)
B、Float.parseFloat(“123”)
C、Integer.valueOf(“123”).initValue()
D、以上都不是
-
现有 1. class Calc { 2. public static void main(String [] args) { 3. try { 4. int x = Integer.parselnt ("42a") ; 5. //insert code here 6. System.out.print ("oops"); 7. } 8. } 9. } 下面哪两行分别插入到第五行,会导致输 "oops" ? ()
A} catch (IllegalArgumentException e) {
B} catch (IllegalStateException c) {
C} catch (NumbelFormatException n) {
D} catch (ClassCastException c) {