What is true about the following code? (Choose all that apply)
public class Main { protected void finalize() { System.out.println("Roar!"); } //from ww w . ja v a 2 s.co m public static void main(String[] args) { Main m = new Main(); m = null; System.gc(); } }
finalize()
is guaranteed to be called. finalize()
might or might not be called finalize()
is guaranteed not to be called. B, E.
Calling System.gc()
suggests that Java might wish to run the garbage collector.
Java is free to ignore the request, making option E correct.
finalize()
runs if an object attempts to be garbage collected, making option B correct.