Explain the usage of the new operator in Java.
Advertisements
प्रश्न
Explain the usage of the new operator in Java.
स्पष्ट करा
Advertisements
उत्तर
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.
- Object Creation: The
newoperator is used to create an instance of a class in Java. - Memory Allocation: It dynamically allocates memory for the newly created object during program execution.
- Constructor Invocation: It automatically calls the constructor of the class to initialise the object.
- Reference Assignment: It returns a reference to the newly created object, which can be stored in a reference variable.
- Array Creation: The
newoperator is also used to create arrays in Java.
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
