Java Heap vs Stack

Last Updated :
Discuss
Comments

Question 1

Which of the following is stored in Stack Memory in Java?

  • A

    Local variables and method calls

  • B

    Objects and their properties

  • C

    Class-level static variables

  • D

    Only Objects

Question 2

In Java, what is true about Heap Memory?

  • A

    Heap Memory stores method calls and references to variables

  • B

    Heap Memory is where instance objects are created and stored

  • C

    Heap Memory is automatically deallocated when methods return

  • D

    Heap Memory is used for storing thread-related information

Question 3

What happens when a method is invoked in Java?

  • A

    The method’s local variables are stored in Heap Memory

  • B

    The method’s local variables and references are stored in Stack Memory

  • C

    The method’s local variables and references are stored in Method Area

  • D

    The method execution is not related to memory allocation

Question 4

Where are local primitive variables stored in Java?

  • A

    They are stored in Stack Memory

  • B

    They are stored in Heap Memory

  • C

    They are stored in the Method Area

  • D

    They are stored in Permanent Generation

Question 5

When an object is created in Java, where is it stored?

  • A

    Stack Memory

  • B

    Method Area

  • C

    Heap Memory

  • D

    Native Memory

Question 6

Which of the following statements about Stack Memory in Java is true?

  • A

    It is used for allocating objects

  • B

    It is shared by all threads

  • C

    It stores data that can be accessed across threads

  • D

    It is cleared automatically when a method execution ends

Question 7

Which of the following is NOT true about Heap Memory in Java?

  • A

    Objects stored in Heap Memory are accessible across different methods

  • B

    Heap Memory is automatically garbage collected when objects are no longer referenced

  • C

    Memory in Heap is limited and needs to be manually managed

  • D

    Objects stored in Heap Memory are shared among threads

Question 8

In terms of performance, which of the following is true about Stack Memory?

  • A

    It is faster because it follows LIFO (Last-In-First-Out) order

  • B

    It is slower than Heap Memory because of object creation

  • C

    It can handle large objects efficiently

  • D

    It has more memory space compared to Heap Memory

Question 9

How does memory allocation differ between Heap and Stack?

  • A

    Heap Memory is allocated for storing variables, and Stack Memory is used for methods

  • B

    Stack Memory is for variables and method calls, while Heap Memory is for objects

  • C

    Stack Memory stores objects, and Heap Memory stores primitive types

  • D

    Heap Memory is faster, while Stack Memory is slower

Question 10

Which of the following is a characteristic of Heap Memory?

  • A

    It is allocated and deallocated automatically

  • B

    It stores references to variables and method calls

  • C

    It has a limited size that can lead to StackOverflowErrors

  • D

    It is cleared immediately after method execution

There are 10 questions to complete.

Take a part in the ongoing discussion