niusouti.com

单选题在J2EE中,如果去编译并运行下面的代码,在这里假定在当前目录下没有Hello.txt文件: import java.io.*;  public class Mine {  public static void main(String argv[]){      Mine m=new Mine();  System.out.println(m.amethod());   }  public int amethod() {     try {  FileInputStream dis=new File

题目
单选题
在J2EE中,如果去编译并运行下面的代码,在这里假定在当前目录下没有Hello.txt文件: import java.io.*;  public class Mine {  public static void main(String argv[]){      Mine m=new Mine();  System.out.println(m.amethod());   }  public int amethod() {     try {  FileInputStream dis=new FileInputStream("Hello.txt");  }  catch (FileNotFoundException fne) {  System.out.println("No such file found");          return -1;     }  catch(IOException ioe)  { }     finally {  System.out.println("Doing finally");     }  return 0;   } }  结果会输出()。
A

No such file found

B

No such file found -1

C

No such file found doing finally -1

D

0


相似考题
更多“单选题在J2EE中,如果去编译并运行下面的代码,在这里假定在当前目录下没有Hello.txt文件: import java.io.*;  public class Mine {  public static void main(String argv[]){      Mine m=new Mine();  System.out.println(m.amethod());   }  public int amethod() {     try {  FileInputStream dis=new File”相关问题
  • 第1题:

    下列程序的执行结果是 ( ) public class Test { public int aMethod() { satic int i=0; i++; System.out.println(i); } public static void.main(String args[]) { Test test=new Test(); test.aMethod(); }

    A.编译错误

    B.0

    C.1

    D.运行成功,但不输出


    正确答案:A

  • 第2题:

    下列代码的执行结果是public class Test{ public int aMethod(){ static int i=0; i++; System.out.println(i); } public static void main(String args[]){ Test test= new Test(); test. aMethod(); }}

    A.编译错误

    B.0

    C.1

    D.运行成功,但不输出


    正确答案:A
    解析:static不能修饰局部变量。

  • 第3题:

    运行下列程序的结果是 ( ) abstract class MineBase { abstract void amethod(); static int i; } public class Mine extends MineBase { public static void main(String argv[]){ int[]ar=new int[5]; for(i=0;i<ar.length;i++) System.out.println(ar[i]);

    A.打印5个0

    B.编译出错,数组ar[]必须初始化

    C.编译出错,Mine应声明为abstract

    D.出现IndexOutOfBoundes的例外


    正确答案:D

  • 第4题:

    下列代码的编译或执行结果是( )。 public class Myval{ public static void main(string args[]){ MyVal m=new MyVal; aMethod; } public void aMethod{ boolean b[]=new Boolean[5]; System.OUt.println(b[0]); } }

    A.1

    B.null

    C.0

    D.编译错误


    正确答案:A
    A。【解析】boolean类型的变量值只有ture或false,b[0]的默认初始值为false。

  • 第5题:

    阅读下面程序 public class MyVal { public static void main(String[]args) { MyVal m=new MyVal(); m.amethod(); } public void amethod() { boolean b[]=new Boolean[5]; } } 程序编译或运行的结果是

    A.1

    B.null

    C.""

    D.编译不通过


    正确答案:D
    解析:语句boolean b[]=new Boolean[5];存在错误,类型不兼容,左边为基本类型,右边为类java.lang.Boolean。Boolean类将基本类型为boolean的值包装在一个对象中。一个Boolean类型的对象只包含一个类型为boolean的字段。

  • 第6题:

    以下代码的调试结果?public class Q {public static void main(String argv[]) {int anar[]= new int[5];System.out.println(anar[0]);}}

    A. 编译错误:anar 在引用前未初始化。

    B. null

    C. 0

    D. 5


    正确答案:C


  • 第7题:

    以下程序的编译和运行结果为?

    abstract class Base{

    abstract public void myfunc();

    public void another(){

    System.out.println("Another method");

    }

    }

    public class Abs extends Base{

    public static void main(String argv[]){

    Abs a = new Abs();

    A.amethod();

    }

    public void myfunc(){

    System.out.println("My Func");

    }

    public void amethod(){

    myfunc();

    }

    }

    A.输出结果为 My Func

    B.编译指示 Base 类中无抽象方法

    C.编译通过,但运行时指示Base 类中无抽象方法

    D.编译指示Base 类中的myfunc方法无方法体,没谁会喜欢该方法。


    正确答案:A

  • 第8题:

    以下程序的调试结果为?class Base{public final void amethod(){System.out.println("amethod");}}public class Fin extends Base{public static void main(String argv[]){Base b = new Base();b.amethod();}}

    A.编译指示带有final 方法的类自己必须定义为final

    B.编译指示不能继承含有final 方法的类

    C.运行错误,原因是Base类没有定义为final类

    D.运行输出 amethod


    正确答案:D

  • 第9题:

    下列程序创建了一个线程并运行,请在下划线处填入正确代码。

    public class Try extends Thread{

    public static void main(String args[]){

    Threadt=new Try();

    【 】;

    }

    public void run(){

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

    }

    }


    正确答案:i
    i

  • 第10题:

    在J2EE中,如果去编译并运行下面的代码,在这里假定在当前目录下没有Hello.txt文件: import java.io.*;  public class Mine {  public static void main(String argv[]){      Mine m=new Mine();  System.out.println(m.amethod());   }  public int amethod() {     try {  FileInputStream dis=new FileInputStream("Hello.txt");  }  catch (FileNotFoundException fne) {  System.out.println("No such file found");          return -1;     }  catch(IOException ioe)  { }     finally {  System.out.println("Doing finally");     }  return 0;   } }  结果会输出()。 

    • A、No such file found
    • B、No such file found -1
    • C、No such file found doing finally -1
    • D、0

    正确答案:C

  • 第11题:

    单选题
    下列代码的编译或执行结果是(  )。 public class MyVal{ public static void main(String args[]){ MyVal m = new MyVal(); m.aMethod(); } public void aMethod(){ boolean b[] = new Boolean[5]; System.out.println(b[0]); } }
    A

    1

    B

    null

    C

    0

    D

    编译错误


    正确答案: D
    解析:
    boolean b[]=new Boolean[5];等号左右布尔类型大小写要一致,故会出现编译错误,选项D正确。

  • 第12题:

    单选题
    public class Test {  public static void aMethod() throws Exception {  try {  throw new Exception(); } finally {  System.out.println(“finally”);  }  }  public static void main(String args[]) {  try {  aMethod();  } catch (Exception e) {  System.out.println(“exception”);  }  System.out.println(“finished”);  }  }  What is the result?()
    A

     finally

    B

     exception finished

    C

     finally exception finished

    D

     Compilation fails.


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

  • 第13题:

    如下两个源程序文件,分别编译后,运行Example.class文件,运行结果为______。

    AB.java文件代码如下;

    package test;

    public class AB

    {

    int a=60;

    public void show()

    {

    System.out.println(”a=”+a);

    }

    Example.java文件代码如下:

    import test.AB;

    class Example

    {

    public static void main(String args[])

    {

    AB bj=new AB();

    obj.show();

    }

    }


    正确答案:a=60
    a=60

  • 第14题:

    阅读下面程序 public class My Val{ public static void main(String args[]){ My Val m=new My Val(); m. amethod(); } public void amethod(){ boolean b[]=new Boolean[5]; } } 程序编译或运行结果是

    A.1

    B.null

    C.

    D.编译不能过


    正确答案:C
    解析:编译能通过,但不在控制台输出任何信息。程序只是实例化了一个布尔类型的数组,且由于此数组为局部变量,不会自动初始化,故其中值都为null。

  • 第15题:

    下列程序创建了一个线程并运行,横线处应填入的正确代码是( )。 public class Try extends Thread{ public static void main(String args[]){ Thread t=new Try; ; } public void runf System.out.println(”Try!"); } }

    A.t.start

    B.t.class

    C.t.thread

    D.t.static


    正确答案:A
    A。【解析】start是类Thread的方法,其中start方法用于启动线程,使之从新建状态转入就绪状态并进入就绪队列排队,一旦轮到它来享用CPU资源时,就可以脱离创建它的主线程独立地开始自己的生命周期了。

  • 第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题:

    下列代码实现从文件file.dat中读出第5个字节到变量c中,横线处应该填入下列项中的______。 import java.io.*; public class exl5 { public static void main(String[] args) { try System.out.println((char)c); catch(Exception e) { e.printStackTrace(); } } }

    A.FileInputStream in = new FileInputStream("chl/file.dat"); in.skip(4); int c = in.read();

    B.FileInputStream in = new FileInputStream("chl/file.dat"); in.skip(5); int c = in.read();

    C.Fi2eInputStream in = new FileInputStream("file.dat"); int c = in.read();

    D.RandomAccessFile in = new RandomAccessFile ("chi/file. dat "); in.skip (4); int c = in.readByte();


    正确答案:A

  • 第18题:

    以下的程序的调试结果为?public class MyAr{public static void main(String argv[]) {MyAr m = new MyAr();m.amethod();}public void amethod(){static int i;System.out.println(i);}}

    A. 输出结果为 0

    B. 运行出错

    C. 输出结果为 null

    D. 编译错误


    正确答案:D

  • 第19题:

    以下的程序的调试结果为public class Scope{int i;public static void main(String argv[]){Scope s = new Scope();s.amethod();}public static void amethod(){System.out.println(i);}}

    A. 输出结果为:0

    B. 无输出

    C. 编译错误

    D. 输出null


    正确答案:C

  • 第20题:

    以下的程序的调试结果为?

    public class As{

    int i = 10;

    int j;

    char z= 1;

    boolean b;

    public static void main(String argv[]){

    As a = new As();

    A.amethod();

    }

    public void amethod(){

    System.out.println(j);

    System.out.println(b);

    }

    }

    A.输出0 和false

    B. 输出0 和true

    C. 编译错误,b 未初始化

    D. 编译错误, z 必须赋字符值


    正确答案:A

  • 第21题:

    public class Test {  public static void aMethod() throws Exception {  try {  throw new Exception(); } finally {  System.out.println(“finally”);  }  }  public static void main(String args[]) {  try {  aMethod();  } catch (Exception e) {  System.out.println(“exception”);  }  System.out.println(“finished”);  }  }  What is the result?()  

    • A、 finally
    • B、 exception finished
    • C、 finally exception finished
    • D、 Compilation fails.

    正确答案:C

  • 第22题:

    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

  • 第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.println(j);  }  }  What is the result?()
    A

     0

    B

     1

    C

     2

    D

     Compilation fails.


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

  • 第24题:

    单选题
    在J2EE中,如果去编译并运行下面的代码,在这里假定在当前目录下没有Hello.txt文件: import java.io.*;  public class Mine {  public static void main(String argv[]){      Mine m=new Mine();  System.out.println(m.amethod());   }  public int amethod() {     try {  FileInputStream dis=new FileInputStream("Hello.txt");  }  catch (FileNotFoundException fne) {  System.out.println("No such file found");          return -1;     }  catch(IOException ioe)  { }     finally {  System.out.println("Doing finally");     }  return 0;   } }  结果会输出()。
    A

    No such file found

    B

    No such file found -1

    C

    No such file found doing finally -1

    D

    0


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