不要拿编译器运行,直接写出答案来哦package com.wen.test;public class TestExtends {
public static void main(String[] args) {
A a = new B();
B b = new B();
}
}abstract class A {
abstract void a();
static {
E e = new E();
}
C c = new C();
public A() {
System.out.println("hello,this is a");
a(); }
}class B extends A {
static int b =1;
C c = new C();
void a() {
System.out.println(b);
}
public B() {
System.out.println("hello,this is b");
}}class C {
public C() {
System.out.println("hello,this is c");
}
}class E {
public E() {
System.out.println("static e");
}
}
public static void main(String[] args) {
A a = new B();
B b = new B();
}
}abstract class A {
abstract void a();
static {
E e = new E();
}
C c = new C();
public A() {
System.out.println("hello,this is a");
a(); }
}class B extends A {
static int b =1;
C c = new C();
void a() {
System.out.println(b);
}
public B() {
System.out.println("hello,this is b");
}}class C {
public C() {
System.out.println("hello,this is c");
}
}class E {
public E() {
System.out.println("static e");
}
}
b
hello,this is b
hello,this is a
b
hello,this is b
好像是这样的
hello,this is c
hello,this is b
hello,this is c
hello,this is a
1
hello,this is c
hello,this is b
hello,this is c
hello,this is a
1
hello,this is c
hello,this is b
hello,this is c
hello,this is a
1
hello,this is c
hello,this is b
汗,看看这个
hello,this is a
1
hello,this is c
hello,htis is bstatic e
hello,this is a
1
hello,this is c
hello,htis is b
static 变量 只加载一次哦。。
hello,htis is b
e
c
a
1
c
b
c
a
1
c
b
hello,this is c
hello,this is a
1
hello,this is c
hello,this is b
hello,this is c
hello,this is a
1
hello,this is c
hello,this is b
hello,this is c
hello,this is a
1
hello,this is c
hello,this is b
hello,this is c
hello,this is a
1
hello,this is c
hello,this is b