Java Reference
In-Depth Information
/** set ScreenColor from description in getValue */
protected void decodeColor() {
if (getValue() == null)
myColor = null;
else
myColor = new ScreenColor(getValue());
}
}
We first create a new ColorAttr class that extends the Attr class. The Co-
lorAttr class does everything the Attr class does and adds new behavi-
or. Therefore, the Attr class is the superclass of ColorAttr , and ColorAttr
is a subclass of Attr . The class hierarchy for these classes looks like this,
going bottom-up from subclass to superclass:
The extended ColorAttr class does three primary things:
It provides three constructors: two to mirror its superclass and
one to directly accept a ScreenColor object.
It both overrides and overloads the setValue method of its super-
class so that it can set the color object when the value is changed.
It provides a new getColor method to return a value that is the
color description decoded into a ScreenColor object.
We look at the intricacies of the construction process and the effect of
inheritance on the different class members over the next few sections.
 
Search WWH ::




Custom Search