Creating an object to a class in java

Creating an object to a class means allocating memory to it. Memory allocation takes place in RAM.
class_name obj=new class_name();
class_name : Specifies the class for which object has to be created.
obj : Name of the object. An object is an instance of a class that holds the members of the class. It points out to the memory allocated to the class.
  Note : The reference of the class (in the memory) need not be stored in a variable. It is only needed if we want to access the members of the class.
new : It is a keyword that allocates memory to a class dynamically (at run time)

Creation of an object can also be done by writing the following statement
new class_name();
Here memory is allocated to the class but its reference is not stored in any object as done in the previous step.

Posted by at on

Tags: Java Introduction, Java Objects,