Object Definition:
Object: In order to store the data for the data members of the class, we must create an object.
- Instance (instance is a mechanism of allocating sufficient amount of memory space for data members of a class) of a class is known as an object.
- Class variable is known as an object.
- Grouped item (grouped item is a variable which allows us to store more than one value) is known as an object.
- Value form of a class is known as an object.
- Blue print of a class is known as an object.
- Logical runtime entity is known as an object.
- Real world entities are called as objects.
Syntax to create an object:
<Classname> objectname = new <classname ()>
Classname represents name of the class. objectname represents JAVA valid variable name treated as object. New is called dynamic memory allocation operator.
classname() represents constructor. The new operator will perform two standard actions. They are
1. It allocates amount sufficient amount of memory space for the data members of the class.
2. It takes address of the class and stored in the left hand side variable of above syntax.
We can also create object in following way:
<classname> objName;
objName = new <classname ()>
When an object is declared where value is null. Since there is no memory space for data members of the class. When the object is referenced the value of the object is not null. Since memory space is created for the data members of the class.