11. class Snoochy {  12. Boochybooch;  13. public Snoochy() { booch = new Boochy(this); }  14. }  15.  16. class Boochy {  17. Snoochy snooch;  18. public Boochy(Snoochy s) { snooch = s; }  19. }  And the statements:  21. public static void main(String[] 

题目

11. class Snoochy {  12. Boochybooch;  13. public Snoochy() { booch = new Boochy(this); }  14. }  15.  16. class Boochy {  17. Snoochy snooch;  18. public Boochy(Snoochy s) { snooch = s; }  19. }  And the statements:  21. public static void main(String[] args) {  22. Snoochy snoog = new Snoochy();  23. snoog = null;  24. // more code here  25. }  Which statement is true about the objects referenced by snoog, snooch, and booch immediately after line 23 executes?() 

  • A、 None of these objects are eligible for garbage collection.
  • B、 Only the object referenced by booch is eligible for garbage collection.
  • C、 Only the object referenced by snoog is eligible for garbage collection.
  • D、 Only the object referenced by snooch is eligible for garbage collection.
  • E、 The objects referenced by snooch and booch are eligible for garbage collection.
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

1. class TestA {  2. TestB b;  3. TestA() {  4. b = new TestB(this);  5. }  6. }  7. class TestB {  8. TestA a;  9. TestB(TestA a) {  10. this.a = a;  11. }  12. }  13. class TestAll {  14. public static void main (String args[]) {  15. new TestAll().makeThings(); 16. // ...code continues on  17. }  18. void makeThings() {  19. TestA test = new TestA(); 20. }  21. }  Which two statements are true after line 15, before main completes?()

  • A、 Line 15 causes a stack overflow.
  • B、 An exception is thrown at runtime.
  • C、 The object referenced by a is eligible for garbage collection.
  • D、 The object referenced by b is eligible for garbage collection.
  • E、 The object referenced by a is not eligible for garbage collection.
  • F、 The object referenced by b is not eligible for garbage collection.

正确答案:C,D

第2题:

11. public static void main(String[] args) {  12. Object obj = new Object() {  13. public int hashCode() {  14. returns 42; 15. }  16. };  17. System.out.println(obj.hashCode());  18. }    What is the result? () 

  • A、 42
  • B、 An exception is thrown at runtime.
  • C、 Compilation fails because of an error on line 12.
  • D、 Compilation fails because of an error on line 16.
  • E、 Compilation fails because of an error on line 17.

正确答案:A

第3题:

11.class Snoochy{12.Boochybooch;13.public Snoochy(){booch=newBoochy(this);}14.}15.16.class Boochy{17.Snoochy snooch;18.public Boochy(Snoochys){snooch=s;}19.}And the statements:21.public static void main(String[]args){22.Snoochy snoog=new Snoochy();23.snoog=null;24.//more code here25.}Which statement is true about the objects referenced by snoog,snooch,and booch immediately after line 23 executes?()

A.None of these objects are eligible for garbage collection.

B.Only the object referenced by booch is eligible for garbage collection.

C.Only the object referenced by snoog is eligible for garbage collection.

D.Only the object referenced by snooch is eligible for garbage collection.

E.The objects referenced by snooch and booch are eligible for garbage collection.


参考答案:E

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

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

第6题:

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

第7题:

11. static class A {  12. void process() throws Exception { throw new Exception(); }  13. }  14. static class B extends A {  15. void process() { System.out.println(”B”); }  16. }  17. public static void main(String[] args) {  18. new B().process();  19. }  What is the result?() 

  • A、 B
  • B、 The code runs with no output.
  • C、 Compilation fails because of an error in line 12.
  • D、 Compilation fails because of an error in line 15.
  • E、 Compilation fails because of an error in line 18.

正确答案:A

第8题:

1. public class GoTest {  2. public static void main(String[] args) {  3. Sente a = new Sente(); a.go();  4. Goban b = new Goban(); b.go();  5. Stone c = new Stone(); c.go();  6. }  7. } 8.  9. class Sente implements Go {  10. public void go() { System.out.println(”go in Sente.”); }  11. }  12.  13. class Goban extends Sente {  14. public void go() { System.out.println(”go in Goban”); }  15. }  16.  17. class Stone extends Goban implements Go { }  18.  19. interface Go { public void go(); }  What is the result?() 

  • A、 go in Goban     go in Sente go in Sente
  • B、 go in Sente      go in Sente go in Goban
  • C、 go in Sente     go in Goban go in Goban
  • D、 go in Goban    go in Goban go in Sente
  • E、 Compilation fails because of an error in line 17.

正确答案:C

第9题:

11. public class Test {  12. public void foo() {  13. assert false;  14. assert false;  15. }  16. public void bar(){  17. while(true){  18. assert false;  19. }  20. assert false;  21. }  22. }  What causes compilation to fail?()  

  • A、 Line 13
  • B、 Line 14
  • C、 Line 18
  • D、 Line 20

正确答案:D

第10题:

11.classA {  12. public void process() { System.out.print(”A “); } }  13. class B extends A {  14. public void process() throws RuntimeException {  15. super.process();  16. if (true) throw new RuntimeException();  17. System.out.print(“B”); }}  18. public static void main(String[] args) {  19. try { ((A)new B()).process(); }  20. catch (Exception e) { System.out.print(”Exception “); }  21. }  What is the result?() 

  • A、 Exception
  • B、 A Exception
  • C、 A Exception B
  • D、 A B Exception
  • E、 Compilation fails because of an error in line 14.
  • F、 Compilation fails because of an error in line 19.

正确答案:B

更多相关问题