Last active
December 14, 2015 11:59
-
-
Save doubledouble/5083206 to your computer and use it in GitHub Desktop.
Java父类子类加载
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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