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