This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 435
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: 435
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: 435
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why it gets incremented?