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?
- Heap
- Stack
- Disk
- 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;
}
}
- Heap, Heap
- Stack, stack
- Heap, Stack
- 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
- Compiler and instruction
- Compiler and interpreter
- Copy and compiler
- None
Answer: 2
Q) Garbage collection in Java is
- Unused package in a program automatically gets deleted.
- Memory occupied by objects with no reference is automatically reclaimed for deletion.
- Java deletes all unused java files on the system.
- The JVM cleans output of Java program.
Answer: 2