CMPSC 56 Chapter Notes - Chapter 7-8: Subtyping, Function Overloading, Duplicate Code

17 views2 pages
1 Oct 2017
School
Course
Professor

Document Summary

Subclasses can add new methods and instance variables and they can override the methods it inherits from the superclass. Design a class that represents the common state and behavior. Decide if a subclass needs behaviors (method implementations) that are specific to that particular subclass type. Look for more opportunities to use abstraction by finding two or more subclass that might need common behavior. When you call a method on an object reference, you"re calling the most specific version of the method for that object type. If class b extends class a, class b is-a class a. If you don"t want to completely replace the superclass version of a method, use super. mymethod() followed by whatever you want to add. Instance variables cannot be overridden, but they can be redefined in the subclass. Define a common protocol for a group of classes. Polymorphism = any subclass of a supertype can be substituted where the supertype is expected.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents