Section 6: Overloading, Overriding, Runtime Type and Object Orientation

  • Write code to invoke overridden or overloaded methods and parental or overloaded constructors; and describe the effect of invoking these methods.

  • Write code to construct instances of any concrete class including normal top-level classes and nested classes.

Relevant Sections

Read Sections 6.1 "Single Implementation Inheritance" through Section 6.3 "Chaining Constructors Using this() and super()." See also Sections 4.4 "Constructors," 7.3 "Non-static Member Classes,"and 7.4 "Local Classes" for constructing instances of nested classes.

Study Notes

Pay attention to which casts are allowed between superclasses and subclasses at compile time, and the effect of casts at runtime. Polymorphism is the result of dynamic method binding of overridden methods at runtime, and the binding is based on the actual type of the object, not the type of the reference. It is illegal for overriding methods to contradict the declaration of the overridden methods. Overloaded methods are distinct methods not subject to dynamic method binding. The ability to overload method names is purely a result of methods being identified by the full signature, rather than just by the method name.

Special language constructs allow explicit access to variables and methods in superclasses and in enclosing contexts. Shadowed variables can be accessed, and overriding methods may call the overridden versions of the methods.

Interface and class definitions can be nested. The exact nature of such definitions and the restrictions placed on the definitions depend on the declaration context. Instances of some nested classes are associated with an outer instance. It is important to understand the correlation between an instance of an inner class and the outer class, and what can be accessed from within an inner class and how. There are several ways of declaring nested classes, and this affects the correlation between an instance of an inner class and its outer class.