This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates 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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why it gets incremented?" Watch "Why it gets incremented?" New topic
Author

Why it gets incremented?

Maki Jav
Ranch Hand

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




Thanks,

Maki Jav

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

Joined: Aug 15, 2010
Posts: 230
    
    2

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: 436
True; but the final id is not throwing any exceptions...
John Jai
Bartender

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: 436
Thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Why it gets incremented?