Results 1 to 4 of 4
  1. #1
    yuri0202 is offline Member
    Join Date
    Sep 2014
    Posts
    2
    Rep Power
    0

    Default Question about Garbage Collector

    Hi guys, first of all I want to apologize for my bad english and I'm not even sure if this is the proprely thread to submit my question.
    That's my question:
    In this code, which one of the 3 objects i1,i2,i3 IS NOT elegible for the Garbage Collection(And why) when the method g() starts:
    Java Code:
    class I {
    private I ref;
    private String name;
    public I(String s) {
     name = s;}
    public void referTo ( I i) {
    ref = i;
    }
     
    Class J {
    private I i1 = new I("o1");
    private I i2 = new I ("o2");
    private I i3 = new I ("o3");
    private void f() {
    i1.referTo(i2);
    i2.referTo(i1);
    i3.referTo(i3);
    i3=i1;
    i2=i1;
    g();
    }
    private void g() { }
    public static void main (String[] args) {
    new J().f();
    }
    }
    Options are
    A= o1
    B= o2
    C= o1 and o2
    D= o3

    I thank you in advance,
    Greats, Yuri.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Question about Garbage Collector

    The joke is that most people who apologize for their bad English are actually pretty good at it.

    You first - what do you think is true and why? This is not your question, this is a homework / certification / job interview question and they are designed for you to answer them to prove something; you getting the answer in a forum would defeat the purpose.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    yuri0202 is offline Member
    Join Date
    Sep 2014
    Posts
    2
    Rep Power
    0

    Default Re: Question about Garbage Collector

    Well it means I'm getting better with this language then :) .
    Well this was on my Java exam , I actually answered A, o1, because of this part of the code " i3=i1, i2=i1" But I'm not sure if the method referTo influences somehow the referments.
    I already took the Exams, i just wanted to know if this answer was true in order to guess what my Exams vote will be.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Question about Garbage Collector

    The answer is E. None of the above (carefully read the question and then read the options provided).

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. java garbage collector
    By pankaj81 in forum New To Java
    Replies: 4
    Last Post: 06-03-2011, 07:21 PM
  2. Garbage Collector
    By giorgi in forum New To Java
    Replies: 27
    Last Post: 05-20-2011, 10:09 AM
  3. about garbage collector
    By sudharani in forum New To Java
    Replies: 1
    Last Post: 04-25-2011, 11:25 AM
  4. Q about Garbage Collector
    By m00nchile in forum New To Java
    Replies: 4
    Last Post: 02-05-2010, 05:57 AM
  5. Garbage collector and its impacts
    By RadhaJayalakshmi in forum Advanced Java
    Replies: 1
    Last Post: 07-23-2008, 11:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •