A
Q. How many of the String objects are eligible for garbage collection right before the end of the main method?
Code:
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;
}
String fruit1 = new String("apple");
String fruit2 = new String("orange");
String fruit3 = new String("pear");
fruit3 = fruit1;
fruit2 = fruit3;
fruit1 = fruit2;
}
- Correct Answer - Option(C)
- Views: 3
- Filed under category Java
- Hashtags:
Discusssion
Login to discuss.