There are no instanced of A that will become eligible for garbage collection.
Explicitly setting myA to null marks that instance to be eligible for garbage collection.
Any call on tryIt() causes the private instance of A to be marked for garbage collection.
Private instances of A become eligible for garbage collection when instances of Alpha become 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?()
第2题:
1. class Test { 2. private Demo d; 3. void start() { 4. d = new Demo(); 5. this.takeDemo(d); 6. } 7. 8. void takeDemo(Demo demo) { 9. demo = null; 10. demo = new Demo(); 11. } 12. } When is the Demo object, created on line 3, eligible for garbage collection?()
第3题:
public class Employee{ private String name; public Employee(String name){ this.name = name; } public void display(){ System.out.print(name); } } public class Manager extends Employee{ private String department; public Manager(String name,String department){ super(name); this.department = department; } public void display(){ System.out.println( super.display()+”,”+department); } } 执行语句new Manager(“smith”,”SALES”)后程序的输出是哪项?()
第4题:
public class X { public X aMethod() { return this;} } public class Y extends X { } Which two methods can be added to the definition of class Y?()
第5题:
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?()
第6题:
class A { } class Alpha { private A myA = new A(); void dolt( A a ) { a = null; } void tryIt() { dolt( myA ); } } Which two statements are correct?()
第7题:
Line5
Line6
Line7
Line8
Line9
Line10
第8题:
new Animal().soundOff();
Elephant e = new Alpha1();
Lion 1 = Alpha.get(“meat eater”);
new Alpha1().get(“veggie”).soundOff();
第9题:
After line 5.
After line 9.
After the start() method completes.
When the takeDemo() method completes.
When the instance running this code is made eligible for garbage collection.
第10题:
Line 15 causes a stack overflow.
An exception is thrown at runtime.
The object referenced by a is eligible for garbage collection.
The object referenced by b is eligible for garbage collection.
The object referenced by a is not eligible for garbage collection.
The object referenced by b is not eligible for garbage collection.
第11题:
int foo() { /* more code here */ }
void foo() { /* more code here */ }
public void foo() { /* more code here */ }
private void foo() { /* more code here */ }
protected void foo() { /* more code here */ }
第12题:
public class Thing { }
public class Thing { public Thing() {} }
public class Thing { public Thing(void) {} }
public class Thing { public Thing(String s) {} }
public class Thing { public void Thing() {} public Thing(String s) {} }
第13题:
class One { void foo() {} } class Two extends One { //insert method here } Which three methods, inserted individually at line 14, will correctly complete class Two?()
第14题:
Which two allow the class Thing to be instantiated using new Thing()?
第15题:
interface Animal { void soundOff(); } class Elephant implements Animal { public void soundOff() { System.out.println(“Trumpet”); } } class Lion implements Animal { public void soundOff() { System.out.println(“Roar”); } } class Alpha1 { static Animal get( String choice ) { if ( choice.equalsIgnoreCase( “meat eater” )) { return new Lion(); } else { return new Elephant(); } } } Which compiles?()
第16题:
1.public class GC{ 2.private Objec to; 3.private void doSomethingElse(Object obj){o=obj;} 4.public void doSomething(){ 5.Object o=new Object(); 6.doSomethingElse(o); 7.o=new Object(); 8.doSomethingElse(null); 9.o=null; 10.} 11.} When the doSomething method is called,after which line does the Object created in line 5 become available for garbage collection?()
第17题:
public abstract class Shape { private int x; private int y; public abstract void draw(); public void setAnchor(int x, int y) { this.x = x; this.y = y; } } Which two classes use the Shape class correctly?()
第18题:
Given: 10. class One { 11. void foo() { } 12. } 13. class Two extends One { 14. //insert method here 15. } Which three methods, inserted individually at line 14, will correctly complete class Two?()
第19题:
x.a2();
z.a2();
z.c1();
z.a1();
y.c1();
x.a1();
第20题:
None of these objects are eligible for garbage collection.
Only the object referenced by booch is eligible for garbage collection.
Only the object referenced by snoog is eligible for garbage collection.
Only the object referenced by snooch is eligible for garbage collection.
The objects referenced by snooch and booch are eligible for garbage collection.
第21题:
public void aMethod() {}
private void aMethod() {}
public void aMethod(String s) {}
private Y aMethod() { return null; }
public X aMethod() { return new Y(); }
第22题:
There are no instanced of A that will become eligible for garbage collection.
Explicitly setting myA to null marks that instance to be eligible for garbage collection.
Any call on tryIt() causes the private instance of A to be marked for garbage collection.
Private instances of A become eligible for garbage collection when instances of Alpha become eligible for garbage collection.
第23题:
public class Circle implements Shape { private int radius; }
public abstract class Circle extends Shape { private int radius; }
public class Circle extends Shape { private int radius; public void draw(); }
public abstract class Circle implements Shape { private int radius; public void draw(); }
public class Circle extends Shape { private int radius;public void draw() {/* code here */} }
public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }
第24题:
Foo.beta() is a valid invocation of beta().
Foo.alpha() is a valid invocation of alpha().
Method beta() can directly call method alpha().
Method alpha() can directly call method beta().