click below
click below
Normal Size Small Size show me how
Inheritance Rules
AP CSA inheritance rules
| Term | Definition |
|---|---|
| Rule 1 | Superclass is the parent class. Subclass is the child class. |
| Rule 2 | Subclass inherits methods and variables from the superclass. Constructors for the subclass must be rewritten. |
| Rule 3 | Subclass methods behave the same as the superclass unless they are told otherwise. |
| Rule 4 | The “super” keyword represents the class name of the superclass. It can be used to call the constructor or the methods of the superclass. |
| Rule 5 | A constructor has to be created in the subclass. If the subclass doesn’t use super, it implicitly calls the superclass’ default constructor (no arguments). |
| Rule 6 | All classes have the .equals() and .toString() method because they inherit it from the object class that is the superclass for all other classes. |
| A super class can be implemented as a subclass. It behaves like the subclass (polymorphism). A subclass can not be implemented as a superclass. General to more specific. NOT specific to the general. | |
| Rule 8 | An error will be thrown if the superclass is created as a subclass and a method that only exists in the subclass is called on the object. |