单选题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.ou

题目
单选题
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


相似考题
参考答案和解析
正确答案: C
解析: 暂无解析
更多“单选题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”相关问题
  • 第1题:

    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

  • 第2题:

    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

  • 第3题:

    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

  • 第4题:

    11. class Payload {  12. private int weight;  13. public Payload(int wt) { weight = wt; }  13. public void setWeight(mt w) { weight = w; }  15. public String toString { return Integer.toString(weight); }  16. }  17.  18. public class TestPayload {  19. static void changePayload(Payload p) { 20. /* insert code here */ 21. }  22.  23. public static void main(String[] args) {  24. Payload p = new Payload();  25. p.setWeight(1024);  26. changePayload(p);  27. System.out.println(”The value of p is “+ p);  28. }  29. }  Which statement, placed at line 20, causes the code to print “The value of p is 420.”?() 

    • A、 p.setWeight(420);
    • B、 p.changePayload(420);
    • C、 p = new Payload(420);
    • D、 Payload.setWeight(420);
    • E、 p = Payload.setWeight(420);
    • F、 p = new Payload(); p.setWeight(420);

    正确答案:A

  • 第5题:

    10. class Inner {  11. private int x;  12. public void setX( int x) { this.x = x; }  13. public int getX() { return x; }  14. }  15.  16. class Outer {  17. private Inner y;  18. public void setY( Inner y) { this.y = y; }  19. public Inner getY() { return y; }  20. }  21.  22. public class Gamma {  23. public static void main( String[] args) { 24. Outer o = new Outer(); 25. Inner i = new Inner();  26.int n=10;  27. i.setX(n);  28. o.setY(i);  29. // insert code here  30. System.out.println( o.getY().getX());  31. }  32. }  Which three code fragments, added individually at line 29, produce the output 100?()

    • A、 n = 100;
    • B、 i.setX( 100);
    • C、 o.getY().setX( 100);
    • D、 i = new Inner(); i.setX( 100);
    • E、 o.setY( i); i = new Inner(); i.setX( 100);
    • F、 i = new Inner(); i.setX( 100); o.setY( i);

    正确答案:B,C,F

  • 第6题:

    10. public class MyClass {  11.  12. public Integer startingI;  13. public void methodA() {  14. Integer i = new Integer(25);  15. startingI = i;  16. methodB(i);  17. }  18. private void methodB(Integer i2) {  19. i2 = i2.intValue();  20.  21. }  22. }  If methodA is invoked, which two are true at line 20?()

    • A、 i2 == startingI returns true.
    • B、 i2 == startingI returns false.
    • C、 i2.equals(startingI) returns true.
    • D、 i2.equals(startingI) returns false.

    正确答案:B,C

  • 第7题:

    单选题
    10. public class Hello {  11. String title;  12. int value;  13. public Hello() {  14. title += “ World”;  15. }  16. public Hello(int value) {  17. this.value = value;  18. title = “Hello”;  19. Hello();  20. }  21. }  and:  30. Hello c = new Hello(5);  31. System.out.println(c.title);  What is the result?()
    A

     Hello

    B

     Hello World

    C

     Compilation fails.

    D

     Hello World 5

    E

     The code runs with no output.

    F

     An exception is thrown at runtime.


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

  • 第8题:

    单选题
    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.


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

  • 第9题:

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

  • 第10题:

    单选题
    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; } }


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

  • 第11题:

    单选题
    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.


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

  • 第12题:

    多选题
    10. public class MyClass {  11.  12. public Integer startingI;  13. public void methodA() {  14. Integer i = new Integer(25);  15. startingI = i;  16. methodB(i);  17. }  18. private void methodB(Integer i2) {  19. i2 = i2.intValue();  20.  21. }  22. }  If methodA is invoked, which two are true at line 20?()
    A

    i2 == startingI returns true.

    B

    i2 == startingI returns false.

    C

    i2.equals(startingI) returns true.

    D

    i2.equals(startingI) returns false.


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

  • 第13题:

    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

  • 第14题:

    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

  • 第15题:

    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

  • 第16题:

    Given the following code:    public class Test {  void printValue(int m){  do {  System.out.println("The value is"+m);     }  while( --m > 10 )     }  public static void main(String arg[]) {     int i=10;  Test t= new Test();     t.printValue(i);     }     }  Which will be output?()    

    • A、 The value is 8
    • B、 The value is 9
    • C、 The value is 10
    • D、 The value is 11

    正确答案:C

  • 第17题:

    10. public class Hello {  11. String title;  12. int value;  13. public Hello() {  14. title += “ World”;  15. }  16. public Hello(int value) {  17. this.value = value;  18. title = “Hello”;  19. Hello();  20. }  21. }  and:  30. Hello c = new Hello(5);  31. System.out.println(c.title);  What is the result?() 

    • A、 Hello
    • B、 Hello World
    • C、 Compilation fails.
    • D、 Hello World 5
    • E、 The code runs with no output.
    • F、 An exception is thrown at runtime.

    正确答案:C

  • 第18题:

    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

    正确答案:A

  • 第19题:

    多选题
    10. class Inner {  11. private int x;  12. public void setX( int x) { this.x = x; }  13. public int getX() { return x; }  14. }  15.  16. class Outer {  17. private Inner y;  18. public void setY( Inner y) { this.y = y; }  19. public Inner getY() { return y; }  20. }  21.  22. public class Gamma {  23. public static void main( String[] args) { 24. Outer o = new Outer(); 25. Inner i = new Inner();  26.int n=10;  27. i.setX(n);  28. o.setY(i);  29. // insert code here  30. System.out.println( o.getY().getX());  31. }  32. }  Which three code fragments, added individually at line 29, produce the output 100?()
    A

    n = 100;

    B

    i.setX( 100);

    C

    o.getY().setX( 100);

    D

    i = new Inner(); i.setX( 100);

    E

    o.setY( i); i = new Inner(); i.setX( 100);

    F

    i = new Inner(); i.setX( 100); o.setY( i);


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

  • 第20题:

    单选题
    Given:   11. public static void main(String[] args) {   12. Object obj = new int[] { 1, 2, 3 };   13. int[] someArray = (int[])obj;   14. for (int i : someArray) System.out.print(i + " ");   15. }   What is the result? ()
    A

     Compilation fails because of an error in line 13.

    B

     A ClassCastException is thrown at runtime.

    C

     1 2 3

    D

     Compilation fails because of an error in line 14.

    E

     Compilation fails because of an error in line 12.


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

  • 第21题:

    单选题
    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.


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

  • 第22题:

    单选题
    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.


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

  • 第23题:

    单选题
    11. class Payload {  12. private int weight;  13. public Payload(int wt) { weight = wt; }  13. public void setWeight(mt w) { weight = w; }  15. public String toString { return Integer.toString(weight); }  16. }  17.  18. public class TestPayload {  19. static void changePayload(Payload p) { 20. /* insert code here */ 21. }  22.  23. public static void main(String[] args) {  24. Payload p = new Payload();  25. p.setWeight(1024);  26. changePayload(p);  27. System.out.println(”The value of p is “+ p);  28. }  29. }  Which statement, placed at line 20, causes the code to print “The value of p is 420.”?()
    A

     p.setWeight(420);

    B

     p.changePayload(420);

    C

     p = new Payload(420);

    D

     Payload.setWeight(420);

    E

     p = Payload.setWeight(420);

    F

     p = new Payload(); p.setWeight(420);


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