jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Why it gets incremented? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why it gets incremented?" Watch "Why it gets incremented?" New topic

Why it gets incremented?

Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Why is the final int id gets incremented?


Maki Jav

Help gets you when you need it!
Raymond Tong
Ranch Hand

Joined: Aug 15, 2010
Posts: 230

nextId is like a visitor counter
id is the snapshot of visitor counter

nextId uniqueness ensured by calling nextId++ when each instance created
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
True; but the final id is not throwing any exceptions...
John Jai

Joined: May 31, 2011
Posts: 1776
The final variable id never gets incremented and always have the value that it has been initialized with.

While creating different objects, the static nextId gets incremented and assigned to the instance variable id - but once assigned the id variable stays unmodified for the instance with which it's associated.

Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
I agree. Here's the link: http://aspose.com/file-tools
subject: Why it gets incremented?
Similar Threads
new to write code, pls help!
Why must non-static inner classes declare static fields final?
Ques on operator
why not static members in inner classes?
Random question