CS 112 - Week 12 Lecture 2 - 2022-11-10
TODAY WE WILL
* announcements
* continue intro to inheritance
* prep for next class
* watch for class e-mails as parts of the delayed Homework 9
are posted; (to be due 11:59 pm on Friday, November 18)
* Reading - still Savitch Ch. 15
=====
TRYING AGAIN:
redefining vs. overloading
=====
* a derived class can define methods unique to that
class (like set_color and get_color in ColorPoint --
those are NOT part of base class Point)
* but it can also have REDEFINED methods
and OVERLOADED methods;
redefined: means you want this version of a method
to REPLACE one it would otherwise inherit
from the base class;
when you call a ColorPoint's method display,
its REDEFINED method display is called,
not base class Point's method display
overloading: means I'd like to have
MORE than one methos with the same
name (and different-enough arguments that
the compiler can tell which is intended)
When you overload a method, you generally
get an additional method version available;
=====
WITHIN A DERIVED CLASS' METHODS:
calling a base class'
version of a method (in general)
=====
* put the base class name, the SCOPE RESOLUTION operator ::,
and the desired base class method:
Point::to_string()
=====
WITHIN A FUNCTION USING A DERIVED CLASS OBJECT:
calling a base class'
version of a method (in general)
=====
* put the base class name, the SCOPE RESOLUTION operator ::,
and the desired base class method -- BUT put these AFTER
the derived-class object's expression and its dot operator:
ColorPoint cp;
cp.Point::to_string()