English

Explain the usage of the new operator in Java.

Advertisements

Question

Explain the usage of the new operator in Java.

Explain
Advertisements

Solution

The new operator in Java is used to create an object or instance of a class dynamically during program execution. It allocates memory for the object and invokes the constructor of the class to initialise the object.

  1. Object Creation: The new operator is used to create an instance of a class in Java.
  2. Memory Allocation: It dynamically allocates memory for the newly created object during program execution.
  3. Constructor Invocation: It automatically calls the constructor of the class to initialise the object.
  4. Reference Assignment: It returns a reference to the newly created object, which can be stored in a reference variable.
  5. Array Creation: The new operator is also used to create arrays in Java.
shaalaa.com
  Is there an error in this question or solution?
Chapter 4: Objects - EXERCISE [Page 107]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 4 Objects
EXERCISE | Q 8. | Page 107
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×