Q.1

public Object m() 
{  
    Object o = new Float(3.14F); 
    Object [] oa = new Object[l];
    oa[= o; /* Line 5 */
    o = null;  /* Line 6 */
    oa[= null; /* Line 7 */
    return o; /* Line 8 */
}
When is the Float object, created in lineeligible for garbage collection?
  • just after line 5
  • just after line 6
  • just after line 7
  • just after line 8
Q.2

void start() {  
    A a = new A(); 
    B b = new B(); 
    a.s(b);  
    b = null; /* Line 5 */
    a = null;  /* Line 6 */
    System.out.println("start completed"); /* Line 7 */
} 
When is the B object, created in lineeligible for garbage collection?
  • after line 5
  • after line 6
  • after line 7
  • There is no way to be absolutely certain.
Q.3

class X
{
    public X2 x;
    public static void main(String [] args) 
    {
        X2 x2 = new X2();  /* Line 6 */
        X2 x3 = new X2();  /* Line 7 */
        x2.x = x
        x3.x = x
        x2 = new X2();
        x3 = x/* Line*/
        doComplexStuff();
    }
}
after lineruns, how many objects are eligible for garbage collection?
  • 0
  • 1
  • 2
  • 3
Q.4

What allows the programmer to destroy an object x?

  • x.delete()
  • x.finalize()
  • Runtime.getRuntime().gc()
  • Only the garbage collection system can destroy an object.
Q.5

class HappyGarbage{ 
    public static void main(String args[]) 
    {
        HappyGarbageh = new HappyGarbage01(); 
        h.methodA(); /* Line 6 */
    } 
    Object methodA() 
    {
        Object obj1 = new Object(); 
        Object [] obj2 = new Object[1]; 
        obj2[= obj
        obj1 = null; 
        return obj2[0]; 
    } 
}
Where will be the most chance of the garbage collector being invoked?
  • After line 9
  • After line 10
  • After line 11
  • Garbage collector never invoked in methodA()
Q.6

Which statement is true?

  • Programs will not run out of memory.
  • Objects that will never again be used are eligible for garbage collection.
  • Objects that are referred to by other objects will never be garbage collected.
  • Objects that can be reached from a live thread will never be garbage collected.
Q.7

class Bar { } 
class Test 
{  
    Bar doBar() 
    {
        Bar b = new Bar(); /* Line 6 */
        return b; /* Line 7 */
    } 
    public static void main (String args[]) 
    { 
        Test t = new Test();  /* Line*/
        Bar newBar = t.doBar();  /* Line*/
        System.out.println("newBar"); 
        newBar = new Bar(); /* Line*/
        System.out.println("finishing"); /* Line*/
    } 
}
At what point is the Bar object, created on lineeligible for garbage collection?
  • after line 12
  • after line 14
  • after line 7, when doBar() completes
  • after line 15, when main() completes
Q.8

Which statement is true?

  • All objects that are eligible for garbage collection will be garbage collected by the garbage collector.
  • Objects with at least one reference will never be garbage collected.
  • Objects from a class with the finalize() method overridden will never be garbage collected.
  • Objects instantiated within anonymous inner classes are placed in the garbage collectible heap.
Q.9

class Test 
{  
    private Demo d; 
    void start() 
    {  
        d = new Demo(); 
        this.takeDemo(d); /* Line 7 */
    } /* Line 8 */
    void takeDemo(Demo demo) 
    { 
        demo = null;  
        demo = new Demo(); 
    } 
}
When is the Demo object eligible for garbage collection?
  • After line 7
  • After line 8
  • After the start() method completes
  • When the instance running this code is made eligible for garbage collection.
Q.10

Which statement is true?

  • Memory is reclaimed by calling Runtime.gc().
  • Objects are not collected if they are accessible from live threads.
  • An OutOfMemory error is only thrown if a single block of memory cannot be found that is large enough for a particular requirement.
  • Objects that have finalize() methods always have their finalize() methods called before the program ends.
Q.11

Which statement is true?

  • Calling Runtime.gc() will cause eligible objects to be garbage collected.
  • The garbage collector uses a mark and sweep algorithm.
  • If an object can be accessed from a live thread, it can't be garbage collected.
  • If object 1 refers to object 2, then object 2 can't be garbage collected.
Q.12

public class X 
{
    public static void main(String [] args) 
    {
        X x = new X();
        X x2 = m1(x); /* Line 6 */
        X x4 = new X();
        x2 = x/* Line 8 */
        doComplexStuff();
    }
    static X m1(X mx) 
    {
        mx = new X();
        return mx;
    }
}
After line 8 runs. how many objects are eligible for garbage collection?
  • 0  
  • 1
  • 2
  • 3
0 h : 0 m : 1 s