- public class Main {
- public static void main(String[] args) throws InstantiationException,
- IllegalAccessException {
- new Main().a();
- }
- private void a() throws InstantiationException, IllegalAccessException {
- System.out.println(Inner.class.newInstance());
- System.out.println(Inner.class.newInstance());
- }
- public static class Inner {
- static{
- System.out.println("static init");
- }
- public Inner() {
- System.out.println("construct init");
- }
- @Override
- public String toString() {
- return "haha";
- }
- }
- }
复制代码 输出:
static init
construct init
haha
construct init
haha |