1~

Minter Coder's Blog

Chapter 2 - Soru 35

2021-03-18

35. How many of the String objects are eligible for garbage collection right before the end
of the main method?
public static void main(String[] fruits) {
String fruit1 =new String("apple");
String fruit2 =new String("orange");
String fruit3 =new String("pear");
fruit3 = fruit1;
fruit2 = fruit3;
fruit1 = fruit2;
}
A. None
B. One
C. Two
D. Three

Main methodundan hemen önce hangi String nesneleri çöp toplayıcısı için uygundur ?

Sırasıyla bakalım ;
fruit1 -> apple

fruit2 -> orange

fruit3 -> pear

sonra(fruit3=fruit1);

fruit1 -> apple

fruit2 -> orange

fruit3 -> apple

sonra (fruit2=fruit3)

fruit1 -> apple

fruit2 -> apple

fruit3 -> apple

sonra (fruit1=fruit2 nesnesini göstersin)

fruit1 -> apple

fruit2 -> apple

fruit3 -> apple

 

Görüldüğü gibi orange ve pear nesneleri çöp toplayıcı için uygundur.Cevap Two