Skip to content

Instantly share code, notes, and snippets.

@doubledouble
Last active December 14, 2015 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doubledouble/5083206 to your computer and use it in GitHub Desktop.
Save doubledouble/5083206 to your computer and use it in GitHub Desktop.
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