ritz301
ritz301

Reputation: 351

How to find instance number of an object in java

Is there some function which takes object as an argument and return the instance number of the object?

By instance number I mean:

The first instance of the class has instance number 1, the second has 2 and so on.

Upvotes: 0

Views: 481

Answers (1)

Damien Chesneau
Damien Chesneau

Reputation: 467

In this case you can initialize a private static counter and in object constructor increment it.

Upvotes: 3

Related Questions