class Demo {
int num;
public Demo(){
System.out.println("空参构造方法");
//num = 20;
}
//构造代码块
{
System.out.println("构造代码块");
num = 10;
}
public void method(){
System.out.println("哈哈");
}
}
class CodeBlockDemo {
public static void main(String[] args) {
//局部代码块
/*
{
int x = 5;
System.out.println(x);
}
System.out.println(x);
*/
//-------------------
Demo d = new Demo();
System.out.println(d.num);
d.method();
}
}
|
|