itgle.com

publicclassTestApp{publicstaticvoidmain(String[]args){try{Stringmyname=null;if(myname.length()>2)System.out.print(1”);}catch(NullPointerExceptione){System.out.print(2”);}}}上述程序运行后的输出是哪项?()A.1B.12C.21D.2

题目
publicclassTestApp{publicstaticvoidmain(String[]args){try{Stringmyname=null;if(myname.length()>2)System.out.print(1”);}catch(NullPointerExceptione){System.out.print(2”);}}}上述程序运行后的输出是哪项?()

A.1

B.12

C.21

D.2


相似考题
更多“publicclassTestApp{publicstaticvoidmain(String[]args){try{Stringmyname=null;if(myname.length()>2)System.out.print(1”);}catch(NullPointerExceptione){System.out.print(2”);}}}上述程序运行后的输出是哪项?() ”相关问题
  • 第1题:

    现有:

    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();

    }

    }

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


    参考答案:B, F

  • 第2题:

    staticvoidtest()throwsRuntimeException{try{System.out.print(”test);thrownewRuntimeException();}catch(Exceptionex){System.out.print(”exception);}}publicstaticvoidmain(String[]args){try{test();}catch(RuntimeExceptionex){System.out.print(”runtime);}System.out.print(”end);}Whatistheresult?()

    A.testend

    B.Compilationfails.

    C.testruntimeend

    D.testexceptionend

    E.AThrowableisthrownbymainatruntime.


    参考答案:D

  • 第3题:

    给定以下JAVA代码,这段代码编译运行后输出的结果是( )

    publicclassTest{

    publicstaticintaMethod(inti)throwsException{

    try{

    returni/10;

    }catch(Exceptionex){

    thrownewException("exceptioninaaMothod");

    }finally{

    System.out.print("finally");

    }

    }

    publicstaticvoidmain(String[]args){

    try{

    aMethod(0);

    }catch(Exceptionex){

    System.out.print("exceptioninmain");

    }

    System.out.print("finished");

    }

    }

    A、finallyexceptioninmainfinished

    B、exceptioninmainfinally

    C、finallyfinished

    D、finallyexceptioninmainfinished


    正确答案:C

  • 第4题:

    现有:classBirds{publicstaticvoidmain(String[]args){try{thrownewException();}catch(Exceptione){try{thrownewException();}catch(Exceptione2){System.out.print("inner");}System.out.print("middle");}System.out.print("outer");}}结果是()

    A.innerouter

    B.middleouter

    C.innermiddleouter

    D..编译失败


    参考答案:C

  • 第5题:

    staticvoidtest(){try{Stringx=null;System.out.print(x.toString()+);}finally{System.out.print(finally);}}publicstaticvoidmain(String[]args){try{test();}catch(Exceptionex){System.out.print(”exception);}}Whatistheresult?()

    A.null

    B.finally

    C.nullfinally

    D.Compilationfails.

    E.finallyexception


    参考答案:E