Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Mock test Q

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
I found this Q on 4tests.com
In the following code, which is the earliest statement, where the object originally held in e, may be garbage collected:

1.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.}

Options are
a.Line 7
b.Line 8
c.Line 10
d.Line 11
e.Never
I think the answer is 6 !! but the one mentioned is 7 !!
Please help
 
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the question is not well worded, in the exam that I took few days ago, the asked "After which line...... " and in this case it's safe to choose line 6, but "what is the earliest......" you can say 7, as it's the first -earliest- after the line that makes the object illegible for GC.
Note that we don't really know what the methods the reference e was passed to do with the object, maybe it references it to another variable in another active reachable thread, then the object won't be elligeble for GC, in this case you can choose "One can't know for sure" or "Indeterminate" if it's one of the options...
HTH
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the question means if a line were to be inserted (ie to suggest garbage collection) then where could it be put so that the original object referenced by e could be collected.
I think your assumption that 'after line 6' is correct.
 
Jon Kidd
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In response to Alfreds reply, Alfred - are we expected to make decisions like that in the exam ? I mean in the example given above then I would just go with what's written but are you saying that if one of the answers was 'indeterminate' then we should go with that ?
 
Alfred Kemety
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the questions in the exam are not like the one above, they are more specific generally, so you won't need to guess...
There were some questions that was not so clear and I did report about them and complained so hopfully by the time you take the exam, it will all be fine.
Just put my notes in mind and if you find something similar in the exam then you know what to choose.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic