In Java in order to create an object ,we must follow dynamic memory allocation by using new operator.
new operator is known as dynamic memory allocation operator.
operations of 'new':
1. It allocates sufficient amount of memory space for the data members of the class.
2. It takes an address of created memory space or address of the class and placed into object name.
Syntax:
(or)
<class_name> object_name; //declaration
object_name=new <class_name()>;
class_name is the name of the class.
object_name represents a valid variable name of java.
Whenever an object is declared whose default value is 'null'.Any attempt to use object_name,will result in compile time error.
Whenever an object is referenced whose default value is not 'null'.It simply holds the memory address of the actual object_name.
0 comments:
Post a Comment