Java object


A Java object is a block of memory that is used to store all the instance variables.

In Java, we use “new” keyword to create new objects and allocate memory at run time.

We can create an object from a class by following 3 steps:

  1. Declaration: It is declaration of a variable with name and object type.
  2. Instantiation: It is instantiation of an object using new keyword.
  3. Initialization: It is initialization of a new object using the “new” keyword followed by a constructor call.

Example:

// Declaration
Square sq;

// Instantiation
sq = new Square();

// Initialization
sq.length = 7;