Which statement is true?

Given the code fragment: Which statement is true?

Given the code fragment: Which statement is true?

A.
After line 8, three objects are eligible for garbage collection

B.
After line 8, two objects are eligible for garbage collection

C.
After line 8, one object is eligible for garbage collection

D.
After line 8, none of the objects are eligible for garbage collection



Leave a Reply 4

Your email address will not be published. Required fields are marked *


Biljana

Biljana

2
the first and
the second

Biljana

Biljana

I was wrong
C(only 1)

Roger

Roger

public class Student {
private int age = 0;

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}
}
public class Test {

public static void main(String[] args) {
Student s1 = new Student();
Student s2 = new Student();
Student s3 = new Student();
s1.setAge(1);
s2.setAge(2);
s3.setAge(3);
s1=s2;
s2=s3;
System.out.println(s2.getAge());
s2=null;
System.out.println(s2.getAge());
}

}

==> C it gives a warning,, but compiles