Java Reference
In-Depth Information
The actual object type in line 4 of Listing A-22 is
ClassB
, so at runtime the JVM checks whether
methodA
( ) exists in
ClassB
. On not finding
methodA
( ) in
ClassB
(because it does not exist in
ClassB
),
the JVM checks for the existence of
methodA
( ) in the hierarchy of
ClassB
, because the JVM
considers the fact that there must be
methodA
( ) existing somewhere in the hierarchy of
ClassB
;
otherwise, the compiler would not have approved the call. Since
methodA
( ) exists in
ClassA
, the JVM
executes
methodA
( ) in
ClassA
at runtime.
Summary
This appendix introduced you to the basics of Java and object-oriented programming. You learned
how classes are the basic building blocks of object-oriented programs and how you can instantiate
objects from classes. Next, you were introduced to the three pillars of object-oriented programming:
encapsulation, inheritance, and polymorphism.