Certification tests

    
                     Certification Practice Tests

HOME  | Cisco  | CompTIA  | Oracle } SCJP } CheckPoint | CIW | Microsoft | Books | Bootcamp |  Buy Now!

 

Java Certification: SCJP - Sun Certified Java Programmer Exam  Practice Questions: Exam SCJP 1.6

Declaration and Access Control

Home                                                                 Up         Previous    Next

 

Q2. How can you force garbage collection of an object?

  

          A.   Garbage collection cannot be forced.
         B.   Call System.gc().
         C.   Call System.gc() passing in a reference  to the object to be garbage collected.
         D.   Call Runtime.gc().
         E.    Set all references to the object to new values(null, for example).
      

 

Correct Answer: A

 

Explanation:

         A is correct. Garbage collection cannot be forced.
         B and D are not correct as calling System.gc() or Runtime.gc() is not 100 percent
         reliable, since the garbage collection thread might defer to a thread of higher 
         priority.
         C is incorrect as gc method does not take argument.
         E  makes object to be garbage collected while next time it refers.

 

 

Home                                                                                                          Up       Previous    Next