lecture tuesday, 4/25: inheritance + any questions Terminology + "specific" = a precise class, not a superclass or subclass or other class. + $public$: not hidden from anyone + $protected$: not hidden from subclasses, but hidden from everyone else + $private$: hidden from subclasses and every other class Box/Scope Diagrams and Invoking a Method + every class (eventually) inherits from predefined class Object + when a method is called, think of a *message* being sent + an object "knows" its specific class and searches for the correct implementation (possibly inherited) for that specific class To draw a class: + "specific" = that class /---------\ + draw an $extends$ arrow ------| extends |------> to its immediate superclass \---------/ + draw its static variables and static methods + the class sees: + Its specific static methods and static variables. + The $public$ and $protected$ things its superclasses sees -- follow the $extends$ arrow To draw an object instantiated by $new$: + "specific" = the class/constructor given with $new$ NOTE: ignore where the reference of the new instance goes! + draw it in its specific class (reminder: pay attention to $new$, but ignore where the references goes!) + draw *all* the instance methods and instance variables that you would draw for an instance of its superclass + draw its specific instance methods and instance variables + the object sees: + its specific instance methods and variables + the $public$ and $protected$ instance methods and variables it inherits from its superclasses -- although you also draw the $private$ variables and methods from superclasses, they are not visible to the specific instance methods + whatever its specific class sees (including following the $extends$ arrow) To draw an activation record of method that is invoked: + draw it in "the same place" that it was found + to figure out which implementation to use: + start at the specific class of the *object* (ignore the class given as the type of the reference variable!) + keep searching up the superclass chain until an implementation is found + "implementation-specific" = the class where the implementation is found, *not* the specific class of the object! + draw boxes for the parameters + fill in the values of the parameters + draw boxes for the local variables + run the code for the method inside the activation record -- + the activation record sees: + its parameters and local variables + implementation-specific variables and methods: ignore the specific class of the object! + (Instance methods only): implementation-specific instance variables and instance methods + implementation-specific static variables and static methods Example: pictures for the code posted for the 4/18 lecture