In this section you will learn about new keyword in java. The new keyword is used to create a instance of a class. The new keyword allocates a space in the memory and initialize the object.
A ob1 = new A(12,56);
Shape ob2 = new Shape(ob,32,98);
First line creates the object of A class and second class create an object of shape class.
Each of these statement has three parts, they are as follows :
The new operator instantiate a class by allocating memory
for a new object and returning a reference to that memory. The new operator also
invoke object constructor. The new operator returns a reference to the object it
created. This reference assigned to the variable of the appropriate type like:
A ob = new A();
While using new keyword some points to be remember :
Posted on: June 13, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles