New operator in Java | Java for Beginner | Dynamic Memory Allocation | Java Gtu.


New operator 

The new operator dynamically allocates memory for an object. It has this
general form:

class-var = new classname( );



Here, class-var is a variable of the class type being created. The classname is the name of the class that is being instantiated. The class name followed by parentheses specifies the constructor for the class.

A constructor defines what occurs when an object of a class is created. Constructors are an important part of all classes and have many significant attributes. However, if no explicit constructor is specified, then Java will automatically supply a default constructor.

It is important to understand that new allocates memory for an object during run time.

Post a Comment

1 Comments