参考:http://blog.csdn.net/gxzzxj/article/details/51946144
下面是自己的代码:
public class ChildA extends Father { void add() { System.out.println("A中的ADD"); } }
public class ChildB extends Father { void add() { System.out.println("B中的ADD"); } }
import org.apache.catalina.filters.AddDefaultCharsetFilter; public class Father { public Father() { System.out.println(this); } void add() { System.out.println("父类中的ADD"); } }
public class Main { public static void main(String[] args) { Father a = new ChildA(); a.add(); } }
参考博客的代码及结果
public class Father1 { private int a = 10; Father1() { System.out.println(this instanceof Son); System.out.println(this.a); System.out.println(((Son) this).a); System.out.println(this.getClass().getName()); } public static void main(String[] args) { Father1 s = new Son(); System.out.println(s.a); } }
class Son extends Father1 { public int a = 0; public int b = 1; public Son() { //隐式调用super(); super(); System.out.println("Son类中执行:"+this); } }