1 先看一个外部类的继承
1 public class FatherClass {
2 public FatherClass(){
3 System.out.println("FatherClass create");
4 }
5 }
6
7
1 public class ChildClass extends FatherClass{
2 public ChildClass(){
3 System.out.println("ChildClass create");
4 }
5 public static void main(String[] args) {
6 FatherClass fc = new FatherClass();
7 ChildClass childClass = new ChildClass();
8 }
9 }
10
11
子类ChildClass是FatherClass的外部继承类,运行ChildClass的结果是
FatherClass create
FatherClass create
ChildClass create
2 在来看一个内部类的继承问题
1 public class OuterClass {
2
3 //内部类
4 private class InterClass{
5 public InterClass(){ //内部类的构造函数
6 System.out.println("InterClass create");
7 }
8 }
9
10 //外部类的构造函数
11 public OuterClass(){
12 InterClass in = new InterClass ();
13 System.out.println("OuterClass create");
14 }
15
16 public static void main(String[] args) {
17 OuterClass class1 = new OuterClass();
18 }
19 }
20
21
打印的结果是
InterClass create
OuterClass create
关于类的继承的问题"
trackback:ping="http://www.blogjava.net/wufang5/services/trackbacks/239799.aspx" />
-->