Showing posts with label Integer object. Show all posts
Showing posts with label Integer object. Show all posts

Monday, 13 February 2012

How many objects will be eligible for garbage collection after line 7?

public class TutorialGC
{

public static void main(String [] args)
{


Object a = new Integer(100);   // Line1
Object b = new Long(100);       // Line2
Object c = new String(“100″);  // Line3
a = null;                                        // Line4
a = c;                                             // Line5
c = b;                                             // Line6
b = a;                                             // Line7
// Rest of the code here


}


}

Choices:



  • A. 0

  • B. 1

  • C. 2

  • D. 3

  • E. Code does not compile


Correct choice:



  • B


Explanation: