This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Static Initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Static Initialization" Watch "Static Initialization" New topic
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
    
  13

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]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel/download
 
subject: Static Initialization
 
Similar Threads
Help???
Traps to be aware of in any SCJP test !!!!! :)
static members initialization and static object references
constructor
inheritance question