static void test() {  try {  String x=null;  System.out.print(x.toString() +“ “);  }  finally { System.out.print(“finally “); }  }  public static void main(String[] args) {  try { test(); }  catch (Exception ex) { System.out.print(”exception “); }  }  Wh

题目

static void test() {  try {  String x=null;  System.out.print(x.toString() +“ “);  }  finally { System.out.print(“finally “); }  }  public static void main(String[] args) {  try { test(); }  catch (Exception ex) { System.out.print(”exception “); }  }  What is the result?() 

  • A、 null
  • B、 finally
  • C、 null finally
  • D、 Compilation fails.
  • E、 finally exception

相似考题
参考答案和解析
正确答案:E
更多“static void test()&en”相关问题
  • 第1题:

    根据输出结果填空完成下面程序。 include class Test { private: static int val; in

    根据输出结果填空完成下面程序。

    include<iostream.h>

    class Test

    {

    private:

    static int val;

    int a;

    public:

    static int func( );

    void sfunc(Test &r);

    };

    ______//初始化静态变量val

    int Test::func( )

    {

    return val++;

    }

    void Test::sfunc(Test &r)

    {

    r.a=125;

    cout<<"Result3="<<r.a;

    }

    void main( )

    {

    cout<<"Resultl="<<Test::func( )<<endl;

    Test A;

    cout<<"Result2="<<A.fune( )<<endl;

    A. sfunc(A);

    }

    输出结果为:

    Result1=201

    Result2=202

    Result3=125


    正确答案:int Test::val=200;
    int Test::val=200; 解析:类的静态成员变量必须要进行初始化才能使用,初始化时需要用域限定符::指明该变量所属的类名。

  • 第2题:

    已知有下列类的说明,则下列哪个语句是正确的?public class Test { private float f=1.0f; int m=12; static int n=1; public static void main(String arg[]) { Test t= new Test(); }}

    A.t.f;

    B.this. n

    C.Test.m;

    D.Test.f;


    正确答案:A
    解析:此题主要考查对象的正确使用,其格式为对象名.调用的方法名或变量名。在static方法中,不能使用 this。变量m和f都不是静态成员,所以不能用类名.成员方式访问。

  • 第3题:

    已知有下面的类说明: public class Test4 { private float f=1.0f; int m=12; static int n=1; public static void main(String args[]) { Test4 e=new Test4(); } } 在main()方法中,下面哪个的使用是正确的? ( )

    A.e.f

    B.this.n

    C.Test4.m

    D.Test4.f


    正确答案:A
    解析:该题考查的是怎样引用对象的变量。访问对象成员变量的格式为:对象名.成员变量名。在本题中使用Test4e=newTest4();语句生成了对象并由变量e引用后,可以通过上述格式访问对象的成员f,即e.f。所以本题选A。

  • 第4题:

    下列程序实现对ZIP文件file.zip的检索,在横线处 填入正确的语句( )。 package test; importjava.io.*; import java.util.*; import java.util.zip.*; public class Exam { public static void main(String[]args){ try{ FileInputStream fis=new FileInputStream("test/file. zip"); ZipInputStream zis=new ZiplnputStream(fis); ZipEntry an; while(( )!=null){ en.getName; zis.closeEntry; } zis.close: } catch(Exception e){ printStackTrace; } } }

    A.en=zis.getNextEntry

    B.en= =zis.getNextEntry

    C.en=zis.getEntry

    D.zis.getNextEntry


    正确答案:A
    A。【解析】本题考查Java类实现ZIP数据压缩方式。ZIP压缩文件结构:一个ZIP文件由多个Entry组成,每个Entry有一个唯一的名称,Entry的数据项存储压缩数据。ZiplnputStream实现了ZIP压缩文件的读输入流,支持压缩和非压缩Entry.题目程序中FileInputStreallD_fis=newFilelnputStream("test/file.zip")构造了一个文件输入流,ZiplnputStreamzis=newZiplnputStream(fis)语句利用文件输入流fis构造了一个ZIP输入流,zis.getNextEntry语句返回ZIP文件中的下一个Entry,并将输出流定位在此entry数据项的起始位置.

  • 第5题:

    下列程序的输出结果是 class Demo { void test( ) { Systeme.out.pnnt("NO");} void test(int i) { System.out.print(a);} void test(int a,int b) { System.out.print(a+b);} } class Test { public static void main(String args[ ] ) { Demo de=new Demo( ); de.test( ); de.test(5); de.test(6,8); } }

    A.No 5 6 8

    B.5 6 8 No

    C.No 5 14

    D.8 6 No 5


    正确答案:C
    解析:本题考查的是方法重载的概念及应用,本题中应顺调查用test(),test(5)和test(6,8)方法,所以答案为选项C)。

  • 第6题:

    下列程序的输出结果是 ( ) class Derao { void test() { Systeme.out.print("NO");} void test (int i) {System.out.print(a);} void test(int a,int b) {System.out.print(a+b);} } class Test { public static void main(String args[]) { Demo de=new Demo(); de.test(); de.test5.; de.test(6,8); } }

    A.No568

    B.568No

    C.No514

    D.86No5


    正确答案:C

  • 第7题:

    static void test() throws RuntimeException {  try {  System.out.print(”test “);  throw new RuntimeException();  }  catch (Exception ex) { System.out.print(”exception “); }  }  public static void main(String[] args) {  try { test(); }  catch (RuntimeException ex) { System.out.print(”runtime “); }  System.out.print(”end “);  }  What is the result?() 

    • A、 test end
    • B、 Compilation fails.
    • C、 test runtime end
    • D、 test exception end
    • E、 A Throwable is thrown by main at runtime.

    正确答案:D

  • 第8题:

    Public class test (  Public static void stringReplace (String text)  (  Text = text.replace (‘j’ , ‘i’);  )  public static void bufferReplace (StringBuffer text)  (  text = text.append (“C”)  )   public static void main (String args[]}  (  String textString = new String (“java”);  StringBuffer text BufferString = new StringBuffer (“java”);  stringReplace (textString);  BufferReplace (textBuffer);  System.out.printLn (textString + textBuffer);  )  )   What is the output?()


    正确答案:JAVAJAVA

  • 第9题:

    单选题
    static void test() throws RuntimeException {  try {  System.out.print(”test “);  throw new RuntimeException();  }  catch (Exception ex) { System.out.print(”exception “); }  }  public static void main(String[] args) {  try { test(); }  catch (RuntimeException ex) { System.out.print(”runtime “); }  System.out.print(”end “);  }  What is the result?()
    A

     test end

    B

     Compilation fails.

    C

     test runtime end

    D

     test exception end

    E

     A Throwable is thrown by main at runtime.


    正确答案: C
    解析: 暂无解析

  • 第10题:

    填空题
    Public class test (    Public static void main (String args) (   System.out.printIn (6^3);   )   )   What is the output? ()

    正确答案: 5
    解析: 暂无解析

  • 第11题:

    单选题
    static void test() throws Error {  if (true) throw new AssertionError();  System.out.print(”test “);  }  public static void main(String[] args) {  try { test(); }  catch (Exception ex) { System.out.print(”exception “); }  System.out.print(”elld “);  }  What is the result?()
    A

     end

    B

     Compilation fails.

    C

     exception end

    D

     exception test end

    E

     A Throwable is thrown by main.

    F

     An Exception is thrown by main.


    正确答案: F
    解析: 暂无解析

  • 第12题:

    单选题
    static void test() {  try {  String x=null;  System.out.print(x.toString() +“ “);  }  finally { System.out.print(“finally “); }  }  public static void main(String[] args) {  try { test(); }  catch (Exception ex) { System.out.print(”exception “); }  }  What is the result?()
    A

     null

    B

     finally

    C

     null finally

    D

     Compilation fails.

    E

     finally exception


    正确答案: A
    解析: 暂无解析

  • 第13题:

    已知如下类说明: public class Test { private float f = 1.0f; int m = 12; static int n=1; public static void main(String arg[]) { Test t = new Test(); // 程序代码… } } 如下哪个使用是正确的?()

    A.t.f

    B.this.n

    C.Test.m

    D.Test.n


    正确答案:AD

  • 第14题:

    已知有下列类的说明,则下列( )语句是正确的。 publicClass Test{ private float f=1.0f; int m=12; static int n=1: public static void main(Stringarg[]){ Test t=new Test(): } }

    A.t.f;

    B.this.n;

    C.Test.m;

    D.Test.f;


    正确答案:A

  • 第15题:

    使下列程序正常运行并且输出“Hello!”,横线处应填写的内容是( )。 class Test { public static void main(string[]args){ Test t=new Test; start; } Public void run{ System.out.println("Hello!¨); )

    A.extends Thread

    B.extends Float

    C.extends Iostream

    D.extends Stdio


    正确答案:A
    A。【解析】从后面重写了run方法来看,这是通过继承Thread类,并重写run方法定义线程体,然后创建该子类的对象的方式来创建线程。

  • 第16题:

    下列代码的执行结果是( )。

    public class Test{

    public int aMethod( ){

    static int i=0;

    i++;

    System.out.println(i):

    }

    public static void main (String args[]){

    Trest test=new Test ( );

    test aMethod( ):

    }

    }

    A.编译错误

    B.0

    C.1

    D.运行成功,但不输出

    B.

    C.

    D.


    正确答案:A

  • 第17题:

    下列程序实现对ZIP文件file.zip的检索,在横线处填入正确的语句 package test; import java.io.*: import java.util.*; import java.util.zip.*; public class Exam { public static void main(String[])args){ try{ FileInputStream fis=new FileInputStream("test/file.zip"); ZipInputStreamzis=new ZipInputStream(fis); ZipEntry en; while ((_____)!=null){ en.getName(); zis.closeEntry(); } zis.close(); } catch(Exception e) { e.printStackTrace(); } } }

    A.en = zis.getNextEntry()

    B.en = zis.getNextEntry()

    C.en = zis.getEntry()

    D.zis.getNextEntry()


    正确答案:A
    解析:本题考查Java类实现zip数据压缩方式。zip压缩文件结构:一个zip文件由多个entry组成,每个entry有一个惟一的名称,entry的数据项存储压缩数据。ZipInputStream实现了zip压缩文件的读输入流,支持压缩和非压缩entry。题目程序中FileInputStreamfis=newFileInputStream("test/file,zip")构造了—个文件输入流,ZipInputStreamzis=newZipInputStream(fis)语句利用文件输入流fis构造了一个ZIP输入流,zis.getNextEntry()语句返回ZIP文件中的下一个entry,井将输出流定位在此entry数据项的起始位置,

  • 第18题:

    以下代码的输出结果?public class Test{int x=5;public static void main(String argv[]){Test t=new Test();t.x++;change(t);System.out.println(t.x);}static void change(Test m){m.x+=2;}}

    A. 7

    B. 6

    C. 5

    D. 8


    正确答案:D

  • 第19题:

    Public class test (  Public static void main (String args[])  (  System.out.printIn (6 ^ 3);  )  )   What is the output?()


    正确答案:5

  • 第20题:

    public class Test {  public int aMethod() {  static int i = 0;  i++;  return i;  }  public static void main (String args[]) {  Test test = new Test();  test.aMethod();  int j = test.aMethod();  System.out.println(j);  }  }  What is the result?()  

    • A、 0
    • B、 1
    • C、 2
    • D、 Compilation fails.

    正确答案:D

  • 第21题:

    单选题
    public class Test {  public int aMethod() {  static int i = 0;  i++;  return i;  }  public static void main (String args[]) {  Test test = new Test();  test.aMethod();  int j = test.aMethod();  System.out.println(j);  }  }  What is the result?()
    A

     0

    B

     1

    C

     2

    D

     Compilation fails.


    正确答案: D
    解析: 暂无解析

  • 第22题:

    填空题
    Public class test (    Public static void stringReplace (String text) (    Text = text.replace („j„ , „i„);    )      public static void bufferReplace (StringBuffer text) (    text = text.append (“C”)   )      public static void main (String args ){  String textString = new String (“java”);    StringBuffer text BufferString = new StringBuffer (“java”);      stringReplace (textString);    BufferReplace (textBuffer);      System.out.printIn (textString + textBuffer);    }   )   What is the output?()

    正确答案: javajavaC
    解析: 暂无解析

  • 第23题:

    单选题
    public class test(    public int aMethod()[   static int i=0;   i++;   return I;   )    public static void main (String args){   test test = new test();    test.aMethod();   int j = test.aMethod();   System.out.printIn(j);   ]  }   What is the result?()
    A

     Compilation will fail.

    B

     Compilation will succeed and the program will print “0”

    C

     Compilation will succeed and the program will print “1”

    D

     Compilation will succeed and the program will print “2”


    正确答案: B
    解析: 暂无解析