static void test()&en

题目

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
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

2下列程序实现对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 FilelnputStream("test/file.zip"); ZipInputStream zis = new ZiplnputStream(fis); ZipEntry en; while ((______ )!= null){ en.getName(); zis.closeEntry(); } zis.close(); } catch(Exception e){ e.pfintStackTrace(); }}

A.en = zis. getNextEntry()

B.en == zis.getNextEntry(

C.en=zis. getEntry()

D.zis.getNextEntry()


正确答案:A

第2题:

根据输出结果填空完成下面程序。 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; 解析:类的静态成员变量必须要进行初始化才能使用,初始化时需要用域限定符::指明该变量所属的类名。

第3题:

有如下类定义:

class Test

{

public:

Test(){ a = 0; c = 0;} // ①

int f(int a)const{this->a = a;} // ②

static int g(){return a;} // ③

void h(int

B . {Test::b = b;}; // ④

private:

int a;

static int b;

const int c;

};

int Test::b = 0;

在标注号码的行中,能被正确编译的是

A . ①

B . ②

C . ③

D . ④


正确答案:C

第4题:

已知有下面的类说明: 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。

第5题:

已知有下列类的说明,则下列哪个语句是正确的?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都不是静态成员,所以不能用类名.成员方式访问。

第6题:

请在下划线处填入代码,是程序正常运行并且输出 “ Hello! ”

Class Test 【 15 】 {

Public static void main (String[] arge){

Test t = new Test();

t.start();

}

Public void run(){

System.out.println( “ Hello! ” );

}


正确答案:

第7题:

已知如下类说明: 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

第8题:

下列程序段的输出结果是【 】。

public class Test {

void printValue(int m) {

do {

System.out.println("The value is"+m);

}while (--m>10);

}

public static void main (String args[]) {

int i=10;

Test t= new Test();

t.printValue(i);

}

}


正确答案:Thevalue is 10
Thevalue is 10 解析:本题考查do-while循环的用法。do-while至少执行一次,在执行完do中的内容后,判断while中的条件是否为true。如果为true,就再执行do中的内容,然后再进行判断。依次类推,直到while的判断为false时退出循环,执行循环后面的内容。题目中m的值为10,当程序运行到do-while循环时,程序先执行一次循环然后再作判断,在判断条件--m>10时,其值为false,退出循环。因此只执行了一次输出操作,输出内容为:The value is 10。

第9题:

已知有下列类的说明,则下列( )语句是正确的。 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

第10题:

使下列程序正常运行并且输出“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方法定义线程体,然后创建该子类的对象的方式来创建线程。

更多相关问题