• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Question from JDCert mock exam

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class Test {
2. public static void main (String args []) {
3. Employee e = new Employee("Bob", 48);
4. e.calculatePay();
5. System.out.println(e.printDetails());
6. e = null;
7. e = new Employee("Denise", 36);
8. e.calculatePay();
9. System.out.println(e.printDetails());
10. }
11. }
In the above question when is e eligible for the garbage collection [ they are asking for the earliest]
The correct answer was at line 7.
I took JXam mock exam and I got a similar question there also and they had two choices line 6 and line 7. I picked line 7
but the correct answer there was line 6.
I am confused now.
So Is it line 6 or line 7.
Can anyone explain
Thanx
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question can be slightly ambigous because it asks at what line is it eligible for GC is after line 6, when e is set to null. That is when the Employee("Bob",48); can be GC'd.
So when they say line 6 are they saying after line 6, or do you need to choose line 7 because that is after line 6.
The statement would be better if it the answers said, after line 6, after line 7, etc... then you would know it is after line 6. I believe the exam is more precise and doesn't have it where each answer can be interpreted as the correct answer.
Since the first question said when is the earliest, line 7 would be correct, because that is when line 6 has finished.
[This message has been edited by bill bozeman (edited December 08, 2000).]
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! Punitha,
I would say that they are correct in the answer , the question states that when it is eligible to be garbage collected,
So as soon as it is assigned a null value the object originally referred by e becomes eligible for Garbage Collection.
But the question should be more specific it should not say e but
the object referred by e.
Hope this clears you.
Srinivas
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you have to be careful how things are worded. if it asks at which line is it eligible answer line 7. if it asks after which line is it elegible answer line 6.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I think Randall has a point there
 
reply
    Bookmark Topic Watch Topic
  • New Topic