- It is an instance of class i.e. Instantiation is a process of allocating/creating sufficient memory space for the data members of the class.
- Whenever we create an object, we get sufficient memory space for the data members of the class.
- Class variable Is known as an object.
- Grouped item is known as object i.e. if any variable is holding more than one value then that variable is known as an object.
- Logical runtime entity is known as an object.
- Real world entities are called objects.
- In order to allocate memory space dynamically, we must follow Dynamic Memory Allocation. To allocate the memory space dynamically, we have an operator called ‘new’. The ‘new’ operator is also known as dynamic memory allocation operator.
<ClassName> objName = new <ClassName()>;
e.g.: Student s = new Student ();
- Here, <ClassName> represents the name of the class which is used for creating the object.
- The ‘objName’ represents the java valid variable name and is treated as object which contains the collection of similar or different type of values.
- The ‘new’ is a dynamic memory allocation operator which is used for allocating memory space dynamically.
- The ‘new’ operator has the following functionalities:
- It allocates sufficient memory space for the data members of the class which we specify.
- It takes an address of the class and places it to its left hand side variable i.e. objName.
Reference variable and assignment:
In assignment operation, object reference variable act differently then do variables of a primitive data types. For instance, int a=10,b; b=a; so here the left side variable receives a copy of the value of right side variable. But in object reference assignment is quite different.
For instance, Vehicle car1 = new Vehicle();
Vehicle car2 =car1;
Here both car1 and car2 refer to the same object, here copy of object is not made.