| Author |
Static Initialization
|
Jacob Thomas
Ranch Hand
Joined: May 06, 2003
Posts: 51
|
|
I believe t3 is a static member variable. Then why is it getting reinitialized everytime when you create new Card( object. ie, why is Tag(33 displayed twice in the output? Thanks in advance!
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24051
|
|
t3 is a static member variable, but you assign to it in the constructor of the Card class nonetheless. Of course, since you make that assignment in a constructor, you can see the effects every time the class is instantiated. The "one-time initialization" refers only to the single time that the value "new Tag(3)" is assigned to t3, when the Card class is first loaded and t3 is automatically initialized. You are free, as you've discovered, to assign a value to a static variable as many times as you wish; it's like any other variable in that regard.
|
[Jess in Action][AskingGoodQuestions]
|
 |
 |
|
|
subject: Static Initialization
|
|
|