itgle.com
更多“publicclassTest{privatestaticint[]x;publicstaticvoidmain(String[]args){System.out.println(x[0]);}}Whatistheresult?() ”相关问题
  • 第1题:

    publicclassTest{publicstaticvoidmain(String[]args){Stringstr=NULL;System.out.println(str);}}Whatistheresult?()

    A.NULL

    B.Compilationfails.

    C.Thecoderunswithnooutput.

    D.Anexceptionisthrownatruntime.


    参考答案:B

    NULLshouldbe"null".

  • 第2题:

    publicclassTest{publicstaticvoidmain(String[]args){intx=0;assert(x>0):“assertionfailed”;System.out.println(“finished”);}}Whatistheresult?()

    A.finished

    B.Compilationfails.

    C.AnAssertionErroristhrown.

    D.AnAssertionErroristhrownandfinishedisoutput.


    参考答案:A

    Thisquestionisabittrickybecauseitlacksthefollowinginformation:Itshouldincludeastatementthatsayswhetherornotassertionsareenabled.Iftheyareindeedenabled,the
    correctionanswerisC.butiftheyarenot,thecorrectanswerisA.Assertionsarenotenabledbydefaultsoifthequestionisnotchanged,themostlogicalanswerisA.

  • 第3题:

    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 来明确。

  • 第4题:

    publicclassTest{publicstaticvoidmain(String[]args){intx=0;assert(x>0)?assertionfailed”:assertionpassed”;System.out.println(Finished”);}}Whatistheresult?()

    A.finished

    B.Compilationfails.

    C.AnAssertionErroristhrownandfinishedisoutput.

    D.AnAssertionErroristhrownwiththemessage“assertionfailed”.

    E.AnAssertionErroristhrownwiththemessage“assertionpassed”.


    参考答案:B

  • 第5题:

    packagetest1;publicclassTest1{staticintx=42;}packagetest2;publicclassTest2extendstest1.Test1{publicstaticvoidmain(String[]args){System.out.println(x=+x);}}Whatistheresult?()

    A.x=0

    B.x=42

    C.Compilationfailsbecauseofanerrorinline2ofclassTest2.

    D.Compilationfailsbecauseofanerrorinline3ofclassTest1.

    E.Compilationfailsbecauseofanerrorinline4ofclassTest2.


    参考答案:C