Menu
Question Index
...

public class NullObjects {
    public static void main(String[] args) {
        X x = new X();
        Y y = new Y();
        x.y = y;
        /* LINE A */
        Z z = new Z();
        y.z = z;
        z.x = x;
        /* LINE B */
        y = null;
        z = null;
        /* LINE C */
        z = new Z();
        x.y = new Y();
        z = null;
        /* LINE D */
    }
}
class X {
    Y y;
}
class Y {
    Z z;
}
class Z {
    X x;
}
What are the number of objects which are available for garbage collection at the given lines?


A=2, B=3, C=3, D=5
A=0, B=0, C=0, D=1
A=0, B=0, C=0, D=3
A=0, B=0, C=2, D=3
Compilation Error or Runtime Error

Doubts

Problems

Topic: Other Advanced Topics In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App