单选题public class Test {  public static void add3 (Integer i) {  int val = i.intValue();  val += 3;  i = new Integer(val); }  public static void main(String args[]) {  Integer i = new Integer(0);  add3(i);  System.out.println(i.intValue());  }  }   What is 

题目
单选题
public class Test {  public static void add3 (Integer i) {  int val = i.intValue();  val += 3;  i = new Integer(val); }  public static void main(String args[]) {  Integer i = new Integer(0);  add3(i);  System.out.println(i.intValue());  }  }   What is the result? ()
A

 0

B

 3

C

 Compilation fails.

D

 An exception is thrown at runtime.


相似考题
更多“public class Test {  public static void add3 (Integer i) { ”相关问题
  • 第1题:

    下列代码的执行结果是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不能修饰局部变量。

  • 第2题:

    下面代码的运行结果是 public class Test{ public static void main(String args[]){ for(int i=0; i<3;i++){ if(i<2) continue; System.out.println(i); } } }

    A.0

    B.1

    C.2

    D.3


    正确答案:C
    解析:本题考查简单的Java控制语句。题目非常简单,但还是应该细心。这里应注意continue语句。continue语句是跳过循环体中下面尚未执行的语句,回到循环体的开始继续下一轮的循环。当然,在下一轮循环开始前,要先进行终止条件的判断,以决定是否继续循环。对于for语句,在进行终止条件的判断前,还要先执行迭代语句。题目所给程序中,当i=0和i=1时,都会执行continue语句,而不会执行System.out.println(i)语句,只有当i=2时才执行System.out.println(i)语句,输出为2,选项C正确。

  • 第3题:

    下列程序的运行结果是( )。 public class test{ private String[]data={¨10","10.5"); public void fun{ double s=0: for(int i=0;i<3;j++){ try{ s=s+Integer.parseInt(data[i]); catch(Exception e){ System.out.print("errorl:"+data[i]); } } } public static void main(string[]args){ try{ test d=new test: fun: }catch(Exception e){ System.OUt.println("error2") } } }

    A.errorl:10.5

    B.error2

    C.errorl:10.5 error2

    D.以上都不对


    正确答案:C
    C。【解析】try-catch块是可以嵌套分层的,并且通过异常对象的数据类型来进行匹配,以找到正确的catchblock异常错误处理代码。以下是通过异常对象的数据类型来进行匹配找到正确的catchblock的过程。①首先在抛出异常的try-catch块中查找catchblock,按顺序先与第一个catchblock块匹配,如果抛出的异常对象的数据类型与catchblock中传入的异常对象的临时变量(就是catch语句后面参数)的数据类型完全相同,或是它的子类型对象,则匹配成功,进入到catchblock中执行,否则到第2步;②如果有两个或更多的catchblock,则继续查找匹配第二个、第三个,直至最后一个catchblock,如匹配成功,则进入到对应的catchblock中执行,否则到第3步;③返回到上一级的try-catch块中,按规则继续查找对应的catchblock。如果找到,进入到对应的catchblock中执行,否则到第4步;④再到上上级的try-catch块中,如此不断递归,直到匹配到顶级的try-catch块中的最后一个catchblock,如果找到,进入到对应的catchblock中执行;否则程序将会执行terminate退出。所以本题选C。

  • 第4题:

    下列程序的运行结果是( )。 public class test{ private String[]data={¨10","10.5"}, public void fun( double S=0; for(int i=0;i<3;i++){ try{ s=s+Integer.parseInt(data[i]); catch(Exception e){ System.out.print(“errorl:”+data[i])。 } } } public static void main(string[]args){ try{ test d=new test; fun; }catch(Exception e){ System.out.println("error2") } } }

    A.errorl:10.5

    B.error2

    C.errorl:10.5 error2

    D.以上都不对


    正确答案:C
    C。【解析】try-catch块是可以嵌套分层的,并且通过异常对象的数据类型进行匹配,以找到正确的catchblock异常错误处理代码。以下是通过异常对象的数据类型进行匹配找到正确的catchblock的过程。①首先在抛出异常的try-catch块中查找catchblock,按顺序先与第一个catchblock块匹配,如果抛出的异常对象的数据类型与catchblock中传入的异常对象的临时变量(就是catch语句后面参数)的数据类型完全相同,或是它的子类型对象,则匹配成功,进入catchblock中执行,否则到第②步;②如果有两个或更多的catchblock,则继续查找匹配第二个、第三个,乃至最后一个catchblock,如匹配成功,则进入对应的catchblock中执行,否则到第③步;③返回到上一级的try-catch块中,按规则继续查找对应的catchblock。如果找到,进入对应的catchblock中执行,否则到第4步;④再到上上级的try-catch块中,如此不断递归,直到匹配到顶级的try-catch块中的最后一个catchblock,如果找到,进入到对应的catchblock中执行;否则程序将会执行terminate退出。所以选C。

  • 第5题:

    ( 30 )在程序的下划线处应填入的选项是

    public class Test _________{

    public static void main(String args[]){

    Test t = new Test();

    Thread tt = new Thread(t);

    tt.start();

    }

    public void run(){

    for(int i=0;i<5;i++){

    system.out.println( " i= " +i);

    }

    }

    }

    A ) implements Runnable

    B ) extends Thread

    C ) implements Thread

    D ) extends Runnable


    正确答案:A

  • 第6题:

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


    正确答案:5

  • 第7题:

    public class test (   public static void main(string args) {   int 1= 0;   while (i) {   if (i==4) {   break;  }   ++i;  }   }   )   What is the value of i at line 10?()

    • A、 0
    • B、 3
    • C、 4
    • D、 5
    • E、 The code will not compile.

    正确答案:E

  • 第8题:

    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

  • 第9题:

    单选题
    public class Test {  public static void add3 (Integer i) {  int val = i.intValue();  val += 3;  i = new Integer(val); }  public static void main(String args[]) {  Integer i = new Integer(0);  add3(i);  System.out.println(i.intValue());  }  }   What is the result? ()
    A

     0

    B

     3

    C

     Compilation fails.

    D

     An exception is thrown at runtime.


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

  • 第10题:

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

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

  • 第11题:

    单选题
    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
    解析: 暂无解析

  • 第12题:

    单选题
    public class Test {  public static void leftshift(int i, int j) {  i<<=j;  }  public static void main(String args[])  {  int i = 4, j = 2;  leftshift(i, j);   System.out.printIn(i); }  }     What is the result?()
    A

     2

    B

     4

    C

     8

    D

     16

    E

     The code will not compile.


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

  • 第13题:

    下面程序段的输出结果是 class Base { int i; Base() { add(1); } void add(int v) { i+=v; } void print() { System.out.println(i); } } class Extension extends Base { Extension() { add(2); } void add(int v) { i+=v*2; } } public class Test { public static void main(String args[]) { bogo(new Extension()); } static void bogo(Baseb){ b.add(8); b.print(); } }

    A.9

    B.18

    C.20

    D.22


    正确答案:D
    解析:本题考查继承和构造函数的用法。首先要明确对一个类的继承是指在父类的基础上构建了一个子类,子类继承了父类的方法和状态。题目所给程序段创建的是Extension类的实例,在运行时,从main()函数进入程序,所有调用add()方法的过程将始终和Extension类的add()方法动态绑定。初始值:i=0;创建实例new Extension();先调用父类的默认构造函数Base(),并在父类的默认构造函数中执行add(1),i=0+1×2,所以i=2,再调用子类的默认构造函数Extension(),子类的默认构造函数中执行add(2),i=2+2×2,所以i=6;执行add(8);i=6+8×2,因此,最终i=22,正确答案为选项D。

  • 第14题:

    在下面程序的下画线处应填入的选项是 public class Test______{ public static void main(String args[]) { Test t=new Test(); Thread tt=new Thread(t); tt.start(); } public void run() { for(int i=0;i<5;i++) System.out.println("i="+i); } }

    A.implements Runnable

    B.extends Thread

    C.implements Thread

    D.extends Runnable


    正确答案:A
    解析:创建线程有两种方法:实现java.lang.Runnahle接口和继承Thread类并重写run()方法。从创建线程实例的语句Thread tt=new Thread(t);可以看出本程序将Test类的实例t作为参数传递给Thread类的构造方法,因此是通过实现Runnable接口创建线程。

  • 第15题:

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

    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

  • 第16题:

    设有如下程序

    public class test {

    public static void main(String args[]) {

    Integer intObj=Integer.valueOf(args[args.length-1]);

    int i = intObj.intValue();

    if(args.length >1、

    System.out.println(i);

    if(args.length >0)

    System.out.println(i -1、;

    else

    System.out.println(i - 2、;

    }

    }

    运行程序,输入如下命令:

    java test 2

    则输出为:

    A. test

    B. test -1

    C. 0

    D. 1

    E. 2


    正确答案:D

  • 第17题:

    public class test {  public static void add3 (Integer i)  int val = i.intValue ( );  val += 3;  i = new Integer (val);  } public static void main (String args [ ] )  {  Integer  i = new Integer (0);  add3 (i);  system.out.printIn (i.intValue ( )  );  } What is the result?()  

    • A、 Compilation will fail.
    • B、 The program prints “0”.
    • C、 The program prints “3”.
    • D、 Compilation will succeed but an exception will be thrown at line 3.

    正确答案:B

  • 第18题:

    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

  • 第19题:

    public class Test {  public static void leftshift(int i, int j) {  i<<=j;  }  public static void main(String args[])  {  int i = 4, j = 2;  leftshift(i, j);   System.out.printIn(i); }  }     What is the result?()  

    • A、 2
    • B、 4
    • C、 8
    • D、 16
    • E、 The code will not compile.

    正确答案:B

  • 第20题:

    public class Test {} What is the prototype of the default constructor?()  

    • A、 Test()
    • B、 Test(void)
    • C、 public Test()
    • D、 public Test(void)
    • E、 public void Test()

    正确答案:C

  • 第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 static void add3 (Integer i){  int val = i.intValue ( );   val += 3;   i = new Integer (val);    }     public static void main (String args [ ] )  { Integer i = new Integer (0);    add3 (i);   system.out.printIn (i.intValue ( ) );   }    }   What is the result?()
    A

     Compilation will fail.

    B

     The program prints “0”.

    C

     The program prints “3”.

    D

     Compilation will succeed but an exception will be thrown at line 3.


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

  • 第24题:

    单选题
    public class Test {} What is the prototype of the default constructor?()
    A

     Test()

    B

     Test(void)

    C

     public Test()

    D

     public Test(void)

    E

     public void Test()


    正确答案: D
    解析: The correct answer to this question is C. The default constructor always takes the same access of the class. In this case, the class is public and so does the default constructor.