public static void main(String[] args){
{
int num = 10;
System.out.println(num);
}
System.out.println(num);//編譯錯誤 因為num只活在上面那個局部代碼塊中
}
class student{
//構造代碼塊
{
System.out.println("student's構造代碼塊");
}
public student(){
System.out.println("空參");
}
public student(int num){
System.out.println("帶參");
}
}
class student{
static String school;
//靜態代碼塊
static {
//靜態方法只能調用靜態成員
school = "學校";
System.out.println("student's靜態代碼塊");
}
public student(){
System.out.println("空參");
}
public student(int num){
System.out.println("帶參");
}
}