
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
162
|
Chapter 6: Inheritance
that all classes can use. For example, any class can use the Object.toString( ) method,
which returns a string representation of an object.
Class Method and Class Property Inheritance
A subclass inherits its superclass’s instance methods and properties, plus its class
methods and properties (i.e., those defined with the static attribute). For example, in
the following code, we define a static method, s( ), in the class A. The method s( ) is
inherited by A’s subclass, B.
class A {
public static function s ( ):Void {
trace("A.s( ) was called.");
}
}
class B extends A {
// For this example, class B does not
// define any of its own methods or properties.
}
An inherited class method or property can be accessed via the superclass, as in:
A.s(); // Displays: A.s( ) was called.
or synonymously via the subclass, as in:
B.s(); // Also displays: A.s( ) was called.
Within the body of either class, the method or property can be referred to directly
without the qualifying class name, as in s( ) rather than A.s( ) or B.s( ). However, it’s
generally wise to include the class name when referring to static methods or proper-
ties. We’ll learn why later, under “Member Access from Inherited, Overriding, and
Overridden Instance Methods.”
The class methods and properties of some built-in ...