What does object identity mean in java?

Viewed 8230

I was reading about "Data abstraction" in java language programming that I faced with this phrase:

Objects in java are characterized by three essential properties: state, identity, and behavior. The state of an object is a value from its data type. The identity of an object distinguishes one object from another. It is useful to think of an object’s identity as the place where its value is stored in memory.

Can everyone explain more specifically what is the identity ?

2 Answers

I can think in these two examples from the C++ world.

Example 1: objects a and b are not identical, because they don't share the same memory.

Someclass a;
Someclass b;

Example 2: objects a and b are identical because they point to the same object.

Someclass c;
Someclass* a = &c;
Someclass* b = &c;
Related