静态代码块中的变量为什么不需要声明数据类型?
如下例所示:先执行静态代码块,为什么a=2可以不声明类型?
public class Test
{
static {a=2;}
static int a =1;
static int b = 3;
static{ b=4;}
public static void main(String[] args)
{
System.out.println(a);
System.out.println(b);
}
}
程序运行结果为:
1
4
public class Test
{
static {a=2;}
static int a =1;
static int b = 3;
static{ b=4;}
public static void main(String[] args)
{
System.out.println(a);
System.out.println(b);
}
}
程序运行结果为:
1
4
...全文


Java SE
