What is garbage collection in the context of Java?
- AThe Java Virtual Machine (JVM) checks the output of any Java program and deletes anything that does not make sense at all.
- BThe Operating System periodically deletes all of the Java files available on the system.
- CAny Java package imported in a program and not being used, is automatically deleted.
- DWhen all references to an object are gone, then the memory used by the object is automatically reclaimed.
Show answerHide answer
Correct answer: (D) When all references to an object are gone, then the memory used by the object is automatically reclaimed.
Explanation
Java's garbage collector automatically reclaims the memory of objects that are no longer referenced by any part of the program.