• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static variables

 
Kevin Lam
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
would it cause error when

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

static int x, y;
}

if not, why?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic