COMPSCI 61B Lecture Notes - Lecture 10: Subtyping, Higher-Order Function, Compile Time

47 views5 pages
14 Feb 2019
School
Professor

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)

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents