0% found this document useful (0 votes)
2 views

Section_14_Garbage_Collection_Questions

The document consists of a series of questions related to garbage collection in Java, covering topics such as the role of the Garbage Collector, methods to suggest garbage collection, and the conditions under which objects become eligible for garbage collection. It also addresses the functionality of the finalize() method and scenarios that trigger garbage collection. Overall, it tests knowledge on how Java manages memory and the garbage collection process.

Uploaded by

karimstudy67
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Section_14_Garbage_Collection_Questions

The document consists of a series of questions related to garbage collection in Java, covering topics such as the role of the Garbage Collector, methods to suggest garbage collection, and the conditions under which objects become eligible for garbage collection. It also addresses the functionality of the finalize() method and scenarios that trigger garbage collection. Overall, it tests knowledge on how Java manages memory and the garbage collection process.

Uploaded by

karimstudy67
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Section 14: Garbage Collection

Q1. In Java, which of the following is responsible for automatically reclaiming unused
memory?
• A) Garbage Collector
• B) JVM Optimizer
• C) Memory Manager
• D) System Cleaner

Q2. Which of the following methods can suggest the JVM to run the garbage collector?
• A) System.gc()
• B) Runtime.freeMemory()
• C) System.runGC()
• D) freeMemory()

Q3. When does an object become eligible for garbage collection?


• A) When it is assigned to a new reference
• B) When it is no longer reachable
• C) When it is declared final
• D) When it is assigned a non-null value

Q4. What will happen if the finalize() method is called directly on an object?
• A) The object is immediately garbage collected
• B) finalize() executes, but garbage collection is not forced
• C) The object becomes eligible for garbage collection
• D) It causes a runtime error

Q5. Which type of reference allows an object to be garbage collected in Java?


• A) Weak reference
• B) Strong reference
• C) Constant reference
• D) Static reference

Q6. What does the finalize() method do in Java?


• A) Cleans up resources before garbage collection
• B) Stops garbage collection
• C) Prevents memory leaks
• D) Manually triggers garbage collection
Q7. In which scenario is garbage collection triggered in Java?
• A) When memory is low
• B) Periodically by the JVM
• C) When System.gc() is called
• D) All of the above

Q8. Which statement is true about garbage collection?


• A) It occurs when finalize() is called
• B) It can be forced by the programmer
• C) It is not guaranteed to happen in a specific time
• D) It prevents memory leaks completely

Q9. What happens to an object that is no longer reachable from any live thread?
• A) It remains in memory indefinitely
• B) It is automatically garbage collected
• C) It causes a memory leak
• D) It is saved to disk

Q10. How does Java prevent the application from running out of memory?
• A) By stopping execution of threads
• B) By automatically collecting unreachable objects
• C) By converting unused memory to disk storage
• D) By increasing memory allocation

You might also like