GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — new operator in Java - GeeksforGeeks new operator in JavaLast Updated : 16 Jun, 2026 The new operator in Java is used to create new objects and allocate memory dynamically during program execution. It creates an instance of a class and returns a reference to that object. The new operator plays an important role in object-oriented programming by allowing objects to be created and initialized at runtime.
Syntax
Output Object Created !! Steps to create an objectWhen an object is created in Java, it generally involves three important steps: 1. DeclarationDeclaring a reference variable of a class type. At this stage, no memory is allocated for the object. Only a reference variable is created. Syntax:
Here, s is a reference variable of type Student, but it does not point to any object yet. 2. InstantiationAllocating memory for the object using the new operator. Memory is allocated in the heap, and the reference variable starts pointing to the object. The new operator allocates memory and creates the object.
3. InitializationInitializing the object by invoking the constructor. The constructor initializes the object’s data members.
Using new to Create ArraysThe new operator is also used to create arrays in Java. Syntax:
Output 10 20 30 40 50 Explanation: The Types of Objects Created Using New Operator
Memory Allocation Using newObjects and arrays created using the new operator are stored in heap memory.
Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |