View RSS Feed

Java Object

Instantiating a Class

Rate this Entry
by , 04-26-2012 at 06:03 PM (589 Views)
A class is instantiated by the new operator, by memory allocation for new object and then making reference return to the memory. Object constructor is invoked by the new operator.

A postfix & single argument is required by the new operator: call to constructor. Constructor’s name gives the class name to be instantiated.

A reference is returned by the new operator to the object which has been created. Usually, reference is being assigned to the appropriate type variable.
Java Code:
Point originOne = new Point(23, 94);
New operator thtat returns the reference doesn’t need to get assigned to the variable. Also, directly it can be used in an expression:
Java Code:
int height = new Rectangle().height;

Submit "Instantiating a Class" to Facebook Submit "Instantiating a Class" to Digg Submit "Instantiating a Class" to del.icio.us Submit "Instantiating a Class" to StumbleUpon Submit "Instantiating a Class" to Google

Categories
Tutorial

Comments