Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Java父类子类加载
package test;
/**
*
* @author Administrator
*
*/
public class LoaderTest {
public static void main(String[] args) {
A a;
a = new AB();
a = new AB();
a = new AB("");
a = new AB("");
}
}
class A {
static {
System.out.println("this is parent A static");
}
public A() {
System.out.println("A constructor");
}
public A(String a) {
System.out.println("A constructor with string");
}
}
class AB extends A {
static {
System.out.println("this is B static");
}
public AB() {
System.out.println("B constructor");
}
public AB(String b) {
super(b); // 没有指定调用父类的构造函数,默认调用无参构造函数
System.out.println("B constructor with string");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.