标签:bsp 输出 java 例子 ext pre name static sys
父类和子类的构造方法的调用顺序
(1)Java例子:
package niukewang; public class Dervied extends Base { private String name = "dervied"; public Dervied() { tellName(); printName(); } public void tellName() { System.out.println("Dervied tell name: " + name); } public void printName() { System.out.println("Dervied print name: " + name); } public static void main(String[] args){ new Dervied(); } } class Base { private String name = "base"; public Base() { tellName(); printName(); } public void tellName() { System.out.println("Base tell name: " + name); } public void printName() { System.out.println("Base print name: " + name); } }
(2)输出结果:
Dervied tell name: null Dervied print name: null Dervied tell name: dervied Dervied print name: dervied
标签:bsp 输出 java 例子 ext pre name static sys
原文地址:http://www.cnblogs.com/Berryxiong/p/6246958.html