This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

increment ???

 
ming ming
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

On the above code, why it display 2 for both t1.i and t2.i ?
I taught it only have increment by one!
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You create two instances of T, since i is static member, it belongs to the class, not to any specific instance. Hence, every instance increments the same varibale i, that's to say, that one that belongs to T, every time the constructor of T is invoked.

The case of j is different. It is an instance member, and every instance of T will get a brand new initialized value for j. To this one you assign the number 1 in every case when the constructor of T is invoked.
[ May 27, 2006: Message edited by: Edwin Dalorzo ]
 
Aum Tao
Ranch Hand
Posts: 210
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is reccomended that you use the Class name to refer to the static member instead of the object's instance.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic