classWaitingimplementsRunnable{booleanflag=false;publicsynchronizedvoidrun(){if(flag){flag=false;System.out.print("1");try{this.wait();}catch(Exceptione){}System.out.print("2");}else{flag=true;System.out.print("3");try{Thread.sleep(2000);}catch(Exceptione

题目

classWaitingimplementsRunnable{

booleanflag=false;

publicsynchronizedvoidrun(){

if(flag){

flag=false;

System.out.print("1");

try{this.wait();}catch(Exceptione){}

System.out.print("2");

}

else{

flag=true;

System.out.print("3");

try{Thread.sleep(2000);}catch(Exceptione){}

System.out.print("4");

notify();

}

}

publicstaticvoidmain(String[]args){

Waitingw=newWaiting();

newThread(w).start();

newThread(w).start();

}

}

以下哪两项是正确的?()


相似考题
参考答案和解析
参考答案:A, B
更多“classWaitingimplementsRunnable{booleanflag ”相关问题
  • 第1题:

    下列变量定义不合法的是( )。

    A、boolean flag=false;

    B、int k=1+'k';

    C、char ch="c";

    D、float r=1/2;


    答案:D

  • 第2题:

    以下变量初始化语句中,正确的有 ()

    A.boolean flag = true;

    B.int i = 32;

    C.float r = 10.0;

    D.double pi = 3.1415926;

    E.int value = 32.0;


    boolean flag = true;;int i = 32;;double pi = 3.1415926;

  • 第3题:

    以下语句正确的是()

    A.byte b = 128;

    B.boolean flag = null;

    C.long a = 2147483648L;

    D.float f = 0.9239;


    将students.txt文件还原到school数据库中

  • 第4题:

    下列能够判断Spring容器是否包含ID为proBean的Bean的代码为( )。

    A.boolean flag = beanFactory.containsBean("proBean");

    B.PropertiesBean propertiesBean

    = (PropertiesBean)beanFactory.getBean("proBean");

    C.Class classType = beanFactory.getType("proBean");

    D.PropertiesBean propertiesBean

    = (PropertiesBean)beanFactory.getBean("proBean", PropertiesBean.class);


    参考答案:A

  • 第5题:

    以下赋值语句正确的是()。

    A.int a=081;

    B.boolean flag=1;

    C.float x=3.5;

    D.char m=65;


    由赋值语句的格式我们可知,赋值语句的赋值号左边必须是一个变量,右边可以是任意表达式. 故选D.