java实例变量及方法调用顺序
public class Base { private String name="base"; public Base(){ sayHello(); } void sayHello() { System.out.println("Base hello " + name); } } class Derived extends Base { private String name="Derived"; public Derived(){ sayHello(); } void sayHello() { System.out.println("Derived hello " + name); } } public class Main { public static void main(String[] args) { Base b = new Derived(); } }
Derived hello null Derived hello Derived
爱书网:www.2ibook.com 一个优秀的视频教学网站,大学各专业的名师课程。免费,免费,免费。
QQ群:762080163
QQ群:762080163

浙公网安备 33010602011771号