
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Overriding Methods and Properties
|
173
You wouldn’t ordinarily define class methods (i.e., static methods) and instance
methods (i.e., nonstatic methods) of the same name. Therefore, in the preceding
example, if your invocation of B.m( ) causes an error, you probably just forgot the
static attribute when defining the m( ) method within the B class.
Note that the super operator cannot be used to invoke a superclass’s version of a
class method from within the subclass version. The keyword super can be used only
in instance methods and constructor functions. To access the superclass’s version of
a class method, reference the superclass in the method invocation, as in:
SomeSuperClass.someOverriddenMethod( );
Overriding Properties
Just as instance and class methods can be overridden, so can instance and class prop-
erties. To override a superclass’s property, we add a property definition of the same
name in the subclass. For example, in the following code, for instances of class B, the
instance property
B.p overrides the instance property A.p:
class A {
public var p:Number = 10;
}
class B extends A {
public var p:Number = 15;
}
Remember that overriding a property using a subclass declaration has no effect on
instances of the superclass. Therefore, all instances of class A have an initial value ...