Simple Class Hierarchy - Virtual functions
Previous    Next    Home    Source    Package

  1. Class E1 and class E2 objects both are also of type D (that is, they are also class D objects) as seen by
       D d1 = new E1(2*Integer.parseInt(...
       D d2 = new E2(Integer.parseInt(...
    However, when value is invoked on d1 and d2 it is always the expected version that is invoked. The d, d1, and d2 objects cannot invoke second, a method known to both E1 and E2 objects (the code does not compile). This means d...d2 are really class D objects.