Java Reference
In-Depth Information
As you can see, the constructors are executed in order of derivation.
If you think about it, it makes sense that constructors are executed in order of derivation.
Because a superclass has no knowledge of any subclass, any initialization it needs to per-
form is separate from and possibly prerequisite to any initialization performed by the sub-
class. Therefore, it must complete its execution first.
Superclass References and Subclass Objects
As you know, Java is a strongly typed language. Aside from the standard conversions and
automatic promotions that apply to its primitive types, type compatibility is strictly en-
forced. Therefore, a reference variable for one class type cannot normally refer to an object
of another class type. For example, consider the following program:
Search WWH ::




Custom Search