Java OCA OCP Practice Question 934

Question

Consider the following code:

1. StringBuffer sbuf = new StringBuffer(); 
2. sbuf = null; 
3. System.gc(); 

Choose all true statements:

  • A. After line 2 executes, the StringBuffer object is garbage collected.
  • B. After line 3 executes, the StringBuffer object is garbage collected.
  • C. After line 2 executes, the StringBuffer object is eligible for garbage collection.
  • D. After line 3 executes, the StringBuffer object is eligible for garbage collection.


C.

Note

After line 2 executes, there are no references to the StringBuffer object, so it becomes eligible for garbage collection.




PreviousNext

Related