COMPSCI 61B Lecture Notes - Lecture 10: Subtyping, Higher-Order Function, Compile Time
Document Summary
Inheritance lets us reuse existing code in a superclass while implementing small modifications by overriding a superclass"s methods or writing brand new methods in the subclass. Inheritance also makes it possible to design general data structures and methods using polymorphism. Polymorphism - providing a single interface to entities of different types. The actual behavior is based on the dynamic type (run-time type) -> java automatically selects the right behavior using dynamic method selection. Using the explicit higher order function approach, you have a common way to print out the larger of 2 objects. In contrast, in the subtype polymorphism approach, the object itself makes the choices. Error at the second box because this line assumes that the > operator works with arbitrary object types when it does not. One approach to maximizing a dog array: leave it to the dog class (give up on making a generalized max function and let the dog class define its own max)