Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: can any one explain the solution for this program

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default can any one explain the solution for this program

    Given:
    1. public class GC {
    2. private Object o;
    3. private void doSomethingElse(Object obj) { o = obj; }
    4. public void doSomething() {
    5. Object o = new Object();
    6. doSomethingElse(o);
    7. o = new Object();
    8. doSomethingElse(null);
    9. o = null;
    10. }
    11. }
    When the doSomething method is called, after which line does the Object created in line 5
    become available for garbage collection?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: can any one explain the solution for this program

    Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.

    We won't do your exam/homework for you. If you'd like our input, tell us what you think the answer is and ask us for feedback. Even then, you may not get it.

  3. #3
    Junior Member codepoet's Avatar
    Join Date
    Jul 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: can any one explain the solution for this program

    You will know if an object is eligible for garbage collector if it becomes UNREACHABLE, and this happens when you don't have any reference variable pointing to it. With this knowledge, you will be able to answer that.

Similar Threads

  1. Program solution
    By Jayasree in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 18th, 2014, 01:47 PM
  2. Solution
    By Suresh.athi in forum The Cafe
    Replies: 1
    Last Post: January 19th, 2012, 08:46 AM
  3. Replies: 1
    Last Post: November 6th, 2011, 09:48 PM
  4. Please help me with the solution
    By abhyudayaupadhyay in forum What's Wrong With My Code?
    Replies: 0
    Last Post: July 6th, 2011, 03:21 PM
  5. Replies: 1
    Last Post: December 13th, 2010, 05:13 AM

Tags for this Thread