单选题Given:   11. public void genNumbers() {   12. ArrayList numbers = new ArrayList();   13. for (int i=0; i10; i++) { 14. int value = i * ((int) Math.random());   15. Integer intObj = new Integer(value);   16. numbers.add(intObj);   17. }   18. System.out

题目
单选题
Given:   11. public void genNumbers() {   12. ArrayList numbers = new ArrayList();   13. for (int i=0; i<10; i++) { 14. int value = i * ((int) Math.random());   15. Integer intObj = new Integer(value);   16. numbers.add(intObj);   17. }   18. System.out.println(numbers);   19. }   Which line of code marks the earliest point that an object referenced by intObj becomes a  candidate for garbage collection?()
A

 Line 19

B

 The object is NOT a candidate for garbage collection.

C

 Line 17

D

 Line 16

E

 Line 18

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

11.publicvoidgenNumbers(){12.ArrayListnumbers=newArrayList();13.for(inti=0;i<10;i++){14.intvalue=i*((int)Math.random());15.IntegerintObj=newInteger(value);16.numbers.add(intObj);17.}18.System.out.println(numbers);19.}WhichlineofcodemarkstheearliestpointthatanobjectreferencedbyintObjbecomesacandidateforgarbagecollection?()

A.Line16

B.Line17

C.Line18

D.Line19

E.TheobjectisNOTacandidateforgarbagecollection.


参考答案:D

第2题:

11.public void genNumbers(){ 12.ArrayList numbers=new ArrayList(); 13.for(inti=0;i<10;i++){ 14.intvalue=i*((int)Math.random()); 15.IntegerintObj=newInteger(value); 16.numbers.add(intObj); 17.} 18.System.out.println(numbers); 19.} Which line of code marks the earliest point that an object referenced by intObj becomes a candidate for garbagec ollection?()

  • A、Line16
  • B、Line17
  • C、Line18
  • D、Line19
  • E、The object is NOT a candidate for garbage collection.

正确答案:D

第3题:

下列程序中,实现将封装数据类型Integer和基本数据类型int之间的转换,以及Integer,int类型和String类型之间的转换。请将程序补充完整。

程序运行结果如下:

123

456

456

public class ex7_1{

public static void main(String[]args) {

Integer intObj;

int n;

String s;

intObj = new Integer(123);

n=intObj.__________;

System.out.printin(Integer.toString(n));

s=new String("456");

intObj=Integer._________;

System.out.println(intObj.__________);

n=Integer.parseInt(s);

System.out.println(Integer.toString(n));

}

}


正确答案:intValue() valueOf(s) toString()
intValue() valueOf(s) toString() 解析:本题主要考查Java类库中对简单数据类型的封装以及对封装类型与基本类型之间的转换。解题关键是熟悉基本数据类型的封装,以及一些常用封装类型的常用转换方法,如Integer类的parseInt()方法等。本题中,第1个空,使用intValue()方法将封装对象intObj转换为基本的数据类型int;第2个空,使用valueOf()方法,将字符串转换为封装对象intObj;第3个空,使用toString()方法,将封装对象intObj转换为字符串打印出来,注意,这里不可以加参数。

第4题:

11. class Converter {  12. public static void main(String[] args) {  13. Integer i = args[0];  14. int j = 12;  15. System.out.println(”It is “ + (j==i) + “that j==i.”);  16. }  17. }  What is the result when the programmer attempts to compile the code and run it with the command java Converter 12?() 

  • A、 It is true that j==i.
  • B、 It is false that j==i.
  • C、 An exception is thrown at runtime.
  • D、 Compilation fails because of an error in line 13.

正确答案:D

第5题:

10. interface Foo { int bar(); }  11. public class Sprite {  12. public int fubar( Foo foo) { return foo.bar(); }  13. public void testFoo() {  14. fubar(  15. // insert code here  16.);  17. }  18. }  Which code, inserted at line 15, allows the class Sprite to compile?() 

  • A、 Foo { public int bar() { return 1; } }
  • B、 new Foo { public int bar() { return 1; } }
  • C、 newFoo() { public int bar(){return 1; } }
  • D、 new class Foo { public int bar() { return 1; } }

正确答案:C

第6题:

Given:11.publicvoidgenNumbers(){12.ArrayListnumbers=newArrayList();13.for(inti=0;i<10;i++){14.intvalue=i*((int)Math.random());15.IntegerintObj=newInteger(value);16.numbers.add(intObj);17.}18.System.out.println(numbers);19.}WhichlineofcodemarkstheearliestpointthatanobjectreferencedbyintObjbecomesacandidateforgarbagecollection?()

A.Line19

B.TheobjectisNOTacandidateforgarbagecollection.

C.Line17

D.Line16

E.Line18


参考答案:A

第7题:

11. public static void main(String[] args) {  12. Integer i = uew Integer(1) + new Integer(2);  13. switch(i) {  14. case 3: System.out.println(”three”); break;  15. default: System.out.println(”other”); break;  16. }  17. }  What is the result?() 

  • A、 three
  • B、 other
  • C、 An exception is thrown at runtime.
  • D、 Compilation fails because of an error on line 12.
  • E、 Compilation fails because of an error on line 13.
  • F、 Compilation fails because of an error on line 15.

正确答案:A

第8题:

11.public void genNumbers(){12.ArrayList numbers=new ArrayList();13.for(inti=0;i14.intvalue=i*((int)Math.random());15.IntegerintObj=newInteger(value);16.numbers.add(intObj);17.}18.System.out.println(numbers);19.}Which line of code marks the earliest point that an object referenced by intObj becomes a candidate for garbagec ollection?()

A.Line16

B.Line17

C.Line18

D.Line19

E.The object is NOT a candidate for garbage collection.


参考答案:D

第9题:

11. public void genNumbers() {  12. ArrayList numbers = new ArrayList();  13. for (int i=0; i<10; i++) {  14. int value = i * ((int) Math.random());  15. Integer intObj = new Integer(value);  16. numbers.add(intObj);  17. }  18. System.out.println(numbers);  19. }  Which line of code marks the earliest point that an object referenced by intObj becomes a candidate for garbage collection?() 

  • A、 Line 16
  • B、 Line 17
  • C、 Line 18
  • D、 Line 19
  • E、 The object is NOT a candidate for garbage collection.

正确答案:D

第10题:

1. public class Test { 2. public static String output =””; 3.  4. public static void foo(int i) { 5. try { 6. if(i==1) { 7. throw new Exception(); 8. } 9. output += “1”; 10. } 11. catch(Exception e) { 12. output += “2”; 13. return; 14. } 15. finally { 16. output += “3”;17. } 18. output += “4”; 19. } 20.  21. public static void main(String args[]) { 22. foo(0); 23. foo(1); 24.  25. }26. } What is the value of the variable output at line 23?()


正确答案:13423

更多相关问题