Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 144

Given:

and

What is the result?

    Correct Answer: C

    The 'city' variable is declared as static in the 'Location' class. Static variables are shared among all instances of the class and are not associated with any particular instance. Therefore, setting 'location' to null does not affect the 'city' variable. When the 'Location' object is created, the constructor sets the static 'city' variable to 'San Francisco'. The garbage collection and the nullification of 'location' do not affect the static variable. Hence, when 'Location.city' is printed, it outputs 'San Francisco'.

Discussion
ASPushkinOption: C

Static variables/ fields are not garbage collected. Static variables are only garbage collected when the class loader which has loaded the class in which static field is there is garbage collected in java.

d7bb0b2Option: C

is valid, static field city

OmnisumemOption: C

Tested: C. San Francisco.

StavokOption: C

C is correct TESTED