Recall & Review
beginner
What is the object lifecycle in Java?
The object lifecycle is the series of stages an object goes through: creation, usage, and destruction (garbage collection).
Click to reveal answer
beginner
Which Java keyword is used to create a new object?
The
new keyword is used to create a new object in Java.Click to reveal answer
intermediate
What happens when an object is no longer referenced in Java?
When no references point to an object, it becomes eligible for garbage collection, meaning Java can remove it to free memory.
Click to reveal answer
advanced
What is the role of the
finalize() method in the object lifecycle?The
finalize() method is called by the garbage collector before an object is destroyed, but its use is discouraged in modern Java and deprecated since Java 9.Click to reveal answer
intermediate
Explain the difference between stack and heap in the context of object lifecycle.
The stack stores references and method calls, while the heap stores the actual objects. Objects live in the heap during their lifecycle.
Click to reveal answer
Which stage is NOT part of the Java object lifecycle?
✗ Incorrect
Compilation is a step before running the program and is not part of the object lifecycle.
What keyword do you use to create a new object in Java?
✗ Incorrect
The
new keyword creates a new object instance.When does Java remove an object from memory?
✗ Incorrect
Java removes objects when they have no references and are eligible for garbage collection.
Where are Java objects stored during their lifecycle?
✗ Incorrect
Objects are stored in the heap memory during their lifecycle.
What is the purpose of the
finalize() method?✗ Incorrect
The
finalize() method is called before garbage collection to clean up resources, but its use is discouraged and deprecated in modern Java.Describe the stages of the object lifecycle in Java and what happens at each stage.
Think about how an object is made, used, and then removed.
You got /4 concepts.
Explain how Java manages memory for objects during their lifecycle.
Consider where objects live and how Java frees memory.
You got /4 concepts.