HelloWorld hello = new HelloWorld();
hello.new Inner().show();
到底~到底~到底~干嘛啊~忘光了╮(╯▽╰)╭
hello.new Inner().show();
到底~到底~到底~干嘛啊~忘光了╮(╯▽╰)╭
2018-04-14
程序运行时先执行静态初始化块,然后执行普通初始化快,最后执行构造方法
// 构造方法
public HelloWorld() {
System.out.println("通过构造方法初始化name");
name = "tom";
}
// 静态初始化块
static {
System.out.println("通过静态初始化块初始化age");
age = 20;
}
// 创建对象
HelloWorld hello = new HelloWorld();
// 调用对象的show方法
hello.show();
// 构造方法
public HelloWorld() {
System.out.println("通过构造方法初始化name");
name = "tom";
}
// 静态初始化块
static {
System.out.println("通过静态初始化块初始化age");
age = 20;
}
// 创建对象
HelloWorld hello = new HelloWorld();
// 调用对象的show方法
hello.show();
2018-04-13