The new keyword

The new keyword in java programming language is used to create a new instance of a class or an array.

The new keyword

     

The new keyword in java programming language is used to create a new instance of a class or an array. Keywords are basically reserved words which have specific meaning relevant to a compiler. The new keyword allocates new objects and initialize them.

Syntex:  Here is the syntax that displays how to create an instance of a class or an array by using the new operator.

Creating a simple java object (non array object) by using the new operator.

String sName = new String();

Creating an array object by using the new operator.

Array arr = new Array();

Note: Here are some points that must be considered while creating an instance of a class or an array.

  • The argument that follows the new keyword must be a class name followed by a series of constructor arguments having parentheses.

  • The collection of arguments must be same as the signature of a constructor for the class.

  • The variable type on the left side of the assignment operator must be compatible with the class or interface which is being instantiated.

Advertisements

Ads
Share on Google+Share on Google+

The new keyword

Posted on: May 27, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: The new keyword  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
Chris
June 15, 2012
New keyword

I'm confused about when the new keyword is needed. When I create a new instance of a class, an object, I use 'new'. But in some of my work for class just now, I came across this, // NumberFormat currence = NumberFormat.getCurrencyInstance();// Why is there no 'new' keyword needed after the equal sign?
Ronak
December 16, 2012
about Stuff

your efforts are appreciable.

Ads

 

Ads