This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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
Don't get me started about those stupid light bulbs.
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