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 10

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


obrain

obrain

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

harish

harish

Answer is B.

S1 and S3 are eligible for garbage collection

renko

renko

S1 and S3 are just pointers to objects.

After:
s1 = s3,
s3 = s2, and
s2 = null
s1 is pointing to an object, just like s3 (different object). There is one object that lost all connections and thus eligible for garbage connection.

Some code:
System.out.println(“s1 – “+s1.toString());
System.out.println(“s2 – “+s2.toString());
System.out.println(“s3 – “+s3.toString()+”\n”);

s1 = s3;
System.out.println(“s1 = s3;”);
System.out.println(“s1 – “+s1.toString());
System.out.println(“s3 – “+s1.toString()+”\n”);

s3 = s2;
System.out.println(“s3 = s2;”);
System.out.println(“s1 – “+s1.toString());
System.out.println(“s2 – “+s2.toString());
System.out.println(“s3 – “+s3.toString()+”\n”);

s2 = null;
System.out.println(“s2 = null;”);
System.out.println(“s1 – “+s1.toString()); //s1 points to Student@7852e922
//System.out.println(s2.toString()); //s2 is null
System.out.println(“s3 – “+s3.toString()); //s3 still point to Student@6d06d69c
/*
| s1 points to Student@7852e922
| s2 is null
| s3 points to Student@6d06d69c
| => no pointer to Student@15db9742 => eligible for garbage collection
*/
}
output:
s1 – Student@15db9742 <= eligible for garbage collection
s2 – Student@6d06d69c
s3 – Student@7852e922

s1 = s3;
s1 – Student@7852e922
s3 – Student@7852e922

s3 = s2;
s1 – Student@7852e922
s2 – Student@6d06d69c
s3 – Student@6d06d69c

s2 = null;
s1 – Student@7852e922
s3 – Student@6d06d69c

Venk Hatta

Venk Hatta

Completed 1Z0-803 exam few days ago! Scored 90% (the passing line is 63% now)!!

Had 70 questions in my actual 1Z0-803 test.

Most of the questions are on Giving Code … tell the result, insert CODE, choose the best option …etc.

Only few questions on Java: advantages of the Java exception mechanism, benefits of using ArrayList over array, valid types for switch, Java Exception classes, two-dimensional array, improve the encapsulation of a class, java class declaration … and so on.

Used valid 1Z0-803 dumps from PassLeader (http://www.passleader.com/1z0-803.html) (272q VCE and PDF), almost all questions were same as my 1Z0-803 exam, valid enough for passing until now!