Hi all,
To be precise the most perfect answer to this is " not possible to tell".
Optimally the ans a. line7 is acceptable provided nothing mysterious happens.
Explanation....
In this scenario we have two classes (1)
Test (2) Employee
Now 'e' is a local variable. It is pointing to anobject created at 3rd line of the code. It is invoking 2 methods- (a)calculatePay(), (b)printDetails().
Since the implementation details of these methods are not revealed, it is not possible to say when or whether the object created at 3rd line be eligible for Garbage collection.
What if the Employee class is like this...
//code starts here
class Employee {
static public Employee eAlias;
public void calculatePay() {
// do neccessary codings..
// ...even here...
eAlias = this ;
}
public void printDetails() {
// do the needed codings relevant to your pgm
}
}
// code is over..for class Employee
In such a kind of implementation the object created at 3rd line which was initially pointed by 'e' is getting an alias which is 'eAlias'. This is still accessible for the live thread main. So that object will not be eligible for GC.
So the correct answer is obviously "not possible to say if the method implementation is not given." . If an option 'none of the above' is present, then choose that. Thank You.
Nikhil Kanjulli Menon.
SCJP 1.4