日期:2014-05-20 浏览次数:20908 次
public class Practice
{
static String string = "static filed";
static {
String strings = "static block";
static void show(){ //这是什么错误,求解
System.out.println("a method in static block");
}
}
public static void say() {
System.out.println(Practice.string);
// System.out.println(strings); 如何使用strings?
}
public static void main(String[] args) {
Practice.say();
}
}
public class Practise {
static String string = "static filed";
static {
String strings = "static block";
}
static void show(){ //静态方法不可声明在静态块中
System.out.println("a method in static block");
}
public static void say() {
System.out.println(Practise.string);
// strings 在静态块中,属于方法内的变量,是局部的,外部访问不到
// System.out.println(strings); 如何使用strings?
}
public static void main(String[] args) {
Practise.say();
}
}