Line 19
The object is NOT a candidate for garbage collection.
Line 17
Line 16
Line 18
第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?()
第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?()
第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?()
第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.”?()
第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?()
第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?()
第7题:
Hello
Hello World
Compilation fails.
Hello World 5
The code runs with no output.
An exception is thrown at runtime.
第8题:
three
other
An exception is thrown at runtime.
Compilation fails because of an error on line 12.
Compilation fails because of an error on line 13.
Compilation fails because of an error on line 15.
第9题:
It is true that j==i.
It is false that j==i.
An exception is thrown at runtime.
Compilation fails because of an error in line 13.
第10题:
Foo { public int bar() { return 1; } }
new Foo { public int bar() { return 1; } }
newFoo() { public int bar(){return 1; } }
new class Foo { public int bar() { return 1; } }
第11题:
Line 16
Line 17
Line 18
Line 19
The object is NOT a candidate for garbage collection.
第12题:
i2 == startingI returns true.
i2 == startingI returns false.
i2.equals(startingI) returns true.
i2.equals(startingI) returns false.
第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?()
第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?()
第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?()
第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?()
第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?()
第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?()
第19题:
n = 100;
i.setX( 100);
o.getY().setX( 100);
i = new Inner(); i.setX( 100);
o.setY( i); i = new Inner(); i.setX( 100);
i = new Inner(); i.setX( 100); o.setY( i);
第20题:
Compilation fails because of an error in line 13.
A ClassCastException is thrown at runtime.
1 2 3
Compilation fails because of an error in line 14.
Compilation fails because of an error in line 12.
第21题:
Line16
Line17
Line18
Line19
The object is NOT a candidate for garbage collection.
第22题:
0
3
Compilation fails.
An exception is thrown at runtime.
第23题:
p.setWeight(420);
p.changePayload(420);
p = new Payload(420);
Payload.setWeight(420);
p = Payload.setWeight(420);
p = new Payload(); p.setWeight(420);