Bird
0
0

What does the new keyword do when creating an object in Java?

easy📝 Conceptual Q1 of 15
Java - Classes and Objects
What does the new keyword do when creating an object in Java?
AIt declares a new class
BIt allocates memory and calls the constructor to create the object
CIt deletes an existing object
DIt converts a primitive type to an object
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of new keyword

    The new keyword in Java is used to allocate memory for a new object and then call the constructor to initialize it.
  2. Step 2: Differentiate from other options

    Declaring a class, deleting objects, or converting primitives are not done by new. Only memory allocation and constructor call happen.
  3. Final Answer:

    It allocates memory and calls the constructor to create the object -> Option B
  4. Quick Check:

    Object creation = It allocates memory and calls constructor [OK]
Quick Trick: Remember: new allocates memory and calls constructor [OK]
Common Mistakes:
  • Thinking new declares a class
  • Confusing new with deleting objects
  • Assuming new converts primitives

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes