Instantiating a Class
by, 04-26-2012 at 05:03 PM (574 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.
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:Point originOne = new Point(23, 94);
Java Code:int height = new Rectangle().height;