MCQ on JVM and Java Memory management

MCQ on JVM and Java Memory Management – Multiple choice questions in Java memory management with answers and explanation. 60% of the objective questions are asked in interviews. But, additional has been added to cover memory concept in Java programming.

Q) Where an object of a class get stored?
  1. Heap
  2. Stack
  3. Disk
  4. File

Answer: 1

Q) In what memory area, variable temp and variable card written in main () get stored?
class CreditCard{
	int num;

public class Bank {

	public static void main(String[] args) {
		int temp;
		CreditCard card;

  1. Heap, Heap
  2. Stack, stack
  3. Heap, Stack
  4. Stack, Heap

Answer: 2
Both variable temp and card will be in stack frames. Temp is primitive data type and card is of reference type. Variable card will be used to store the address/ reference of an object of CreditCard class.

Q) Java uses two stage system for program execution. They are
  1. Compiler and instruction
  2. Compiler and interpreter
  3. Copy and compiler
  4. None

Answer: 2

Q) Garbage collection in Java is
  1. Unused package in a program automatically gets deleted.
  2. Memory occupied by objects with no reference is automatically reclaimed for deletion.
  3. Java deletes all unused java files on the system.
  4. The JVM cleans output of Java program.

Answer: 2

MCQ on JVM and Java Memory management
Scroll to top