Bird
0
0

Which of the following Java statements correctly creates an object stored in heap memory?

easy📝 Syntax Q12 of 15
Java - Memory Management Basics
Which of the following Java statements correctly creates an object stored in heap memory?
AString s = new String("hello");
Bint x = 5;
Cdouble y = 3.14;
Dboolean flag = true;
Step-by-Step Solution
Solution:
  1. Step 1: Identify object creation syntax

    Objects in Java are created using the new keyword, which allocates memory on the heap.
  2. Step 2: Check each option

    String s = new String("hello"); uses new String("hello"), which creates a String object on the heap. Other options declare primitives stored on the stack.
  3. Final Answer:

    String s = new String("hello"); -> Option A
  4. Quick Check:

    Object creation uses new keyword [OK]
Quick Trick: Look for 'new' keyword to spot heap allocation [OK]
Common Mistakes:
  • Assuming primitives use heap
  • Confusing string literals with new String()
  • Ignoring that only new creates heap objects

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes