Java Reference
In-Depth Information
T EXT M ESSAGE C LASS
public class TextMessage {
// This member is available to any class.
public String msgText;
// This member is available to any class in this package and to all
// derived classes.
protected int msgSize;
...
}
E RROR M SG C LASS
public class ErrorMsg extends TextMessage {
// This member is available only to derived classes
// and not to other classes in the package.
private protected int counter = 0;
// This member is available to classes in this package.
char msgNumber;
// This member is available only to this class.
private char interfaceInUse;
...
}
A class's methods can also be extended by a subclass. That is, a derived class can
extend the capabilities of its base class's methods. This is called overriding the
method. A derived class might override a base class's method to provide some spe-
cialized version of this method. A consumer class that creates a derived class can,
therefore, call derived functions in the same way (i.e., with the same name and the
same parameters) that the original (or base) function was called. The Java runtime
will figure out which class method to call (in the original class or in the derived
class), based on the actual type of the object. Suppose you have a class hierarchy as
shown in the following sections.
Search WWH ::




Custom Search