• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Javacaps mock exam

 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question is from Javacaps mock 1 Q12
Here the answer given is A but since according to our final discussion string literals are not garbage collected then the answer should be D.
Am i right?

String string1 = "Test";
String string2 = "Today";
string1 = null;
string1 = string2;
A) 1
B) 2
C) 3
D) 0
another question no 11
A) The garbage collector runs in low memory situations
B) You can run the garbage collector when ever you want.
C) When it runs, it releases the memory allocated by an object, which is no more in use.
D) Garbage collector immediately runs when you set the references to null.
Ans given is A and C
but i feel it should be only C
Please someone help
Neha

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neha,
I agree with you 100%.
 
Ranch Hand
Posts: 1246
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree on the first one..
but the second one..
the GC does A) The garbage collector runs in low memory situations
so it is A and C.
correct me if i am wrong.
 
Neha Sawant
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But FEING you cannot be sure when GC occurs so you cannot make a conclusion like the one mentioned
Correct me if i am wrong
Regards
Neha
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi neha
u can not sure when GC is going to run but its true that it runs in low memory situations.
but it is not sure that whether it able to free up the memory or not
i m agree on 1.
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Fei

------------------
coffee drinker
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i agree with vishal.
-maulin.
 
reply
    Bookmark Topic Watch Topic
  • New Topic