/* * Java is a true OO language. Its classes do "dynamic function binding" * which means that the function used is determined by the * object type at the time it was created, not by what it * it is being viewed as. * * @author gtowell * created: Aug 6, 2021 */ public class FuncBind { private class A { public String comment() { return "I am from A"; } } private class B extends A { @Override public String comment() { return "I am from B"; } } public void doTest() { B bb = new B(); A aa = (A) bb; System.out.println("B2: " + bb.comment()); System.out.println("A2: " + aa.comment()); A a3 = new A(); System.out.println("A2: " + a3.comment()); } public static void main(String[] args) { new FuncBind().doTest(); } }