Java Reference
In-Depth Information
P OPUP E RROR M SG C LASS
public class PopupErrorMsg extends ErrorMsg {
public int windowWidth;
public int windowHeight;
}
P RINTFILE E RROR M SG C LASS
public class PrintfileErrorMsg extends ErrorMsg {
public int linesToSkip;
}
C ONSUMER C LASS
A consumer class can use these derived classes in the following way:
// Create new instances of a popup error message and a print file error
// message.
PrintfileErrorMsg myPrintMsg = new PrintfileErrorMsg ();
PopupErrorMsg myPopupMsg = new PopupErrorMsg ();
...
// Capture the length of the popup message myPopupMsg.
// Note that the public member msgSize is defined in the base class
// ErrorMsg.
// Even so, the derived class instance myPopupMsg contains it, and the
// consumer class uses it as if it were part of myPopupMsg.
int len = myPopupMsg.msgSize;
// Now, compare the size of the message to the size of the popup window.
// This public data member is defined in the derived class, not the base
// class.
// Yet the same ID (myPopupMsg) is used.
if (len >= myPopupMsg.windowWidth) {
...
}
Classes that are related through inheritance can use the member access control
protected . The keyword protected extends the visibility of a member to any derived
classes. Using this keyword, a base class can define members that would be appro-
priate for a derived class to access but would not be appropriate for a consumer class.
Search WWH ::




Custom Search