This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes static variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "static variables" Watch "static variables" New topic
Author

static variables

Kevin Lam
Ranch Hand

Joined: Oct 27, 2005
Posts: 68
would it cause error when

public class A()
{
static{int x = 4;}

static int x, y;
}

if not, why?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Assuming that you remove the parentheses from your class definition, there would be no error. The reason is scope: There are two different int x variables declared, and the one assigned a value of 4 is local to the static block.
[ November 21, 2005: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: static variables
 
jQuery in Action, 3rd edition