Here are 10 essential multiple-choice questions on Java Heap vs Stack, covering key concepts.
Question 1
Which of the following is stored in Stack Memory in Java?
Local variables and method calls
Objects and their properties
Class-level static variables
Reference variables
Question 2
In Java, what is true about Heap Memory?
Heap Memory stores method calls and references to variables
Heap Memory is where instance objects are created and stored
Heap Memory is automatically deallocated when methods return
Heap Memory is used for storing thread-related information
Question 3
What happens when a method is invoked in Java?
The method’s local variables are stored in Heap Memory
The method’s local variables and references are stored in Stack Memory
The method’s local variables and references are stored in Method Area
The method execution is not related to memory allocation
Question 4
How are primitive types (e.g., int, char) stored in Java?
They are stored in Stack Memory
They are stored in Heap Memory
They are stored in the Method Area
They are stored in Permanent Generation
Question 5
When an object is created in Java, where is it stored?
Stack Memory
Method Area
Heap Memory
Native Memory
Question 6
Which of the following statements about Stack Memory in Java is true?
It is used for allocating objects
It is shared by all threads
It stores data that can be accessed across threads
It is cleared automatically when a method execution ends
Question 7
Which of the following is NOT true about Heap Memory in Java?
Objects stored in Heap Memory are accessible across different methods
Heap Memory is automatically garbage collected when objects are no longer referenced
Memory in Heap is limited and needs to be manually managed
Objects stored in Heap Memory are shared among threads
Question 8
In terms of performance, which of the following is true about Stack Memory?
It is faster because it follows LIFO (Last-In-First-Out) order
It is slower than Heap Memory because of object creation
It can handle large objects efficiently
It has more memory space compared to Heap Memory
Question 9
How does memory allocation differ between Heap and Stack?
Heap Memory is allocated for storing variables, and Stack Memory is used for methods
Stack Memory is for variables and method calls, while Heap Memory is for objects
Stack Memory stores objects, and Heap Memory stores primitive types
Heap Memory is faster, while Stack Memory is slower
Question 10
Which of the following is a characteristic of Heap Memory?
It is allocated and deallocated automatically
It stores references to variables and method calls
It has a limited size that can lead to StackOverflowErrors
It is cleared immediately after method execution
There are 10 questions to complete.