Declares that a method or property overrides a method or property in a base class.
override statement |
Arguments
- statement
-
Required. A method or property definition.
Remarks
The override modifier is used for a method that overrides a method in a base class. You are not allowed to use the override modifier for a method unless the base class has a member with the same signature.
Methods and properties in classes can be marked with the override modifier. Classes, fields, interfaces and members of interfaces cannot take the override modifier.
You may not combine the override modifier with the other version-safe modifier (hide). The version-safe modifiers cannot be combined with the static modifier. By default, a method will override a base-class method unless the base-class method has the final modifier. You cannot override a final method. When running in version-safe mode, one of the version-safe modifiers must be used whenever a base-class method is overridden.
Example
The following example illustrates a use of the override modifier. The method in the derived class marked with the override modifier overrides the base-class method. The method marked with the hide modifier does not override the base class method.
В | Copy Code |
---|---|
class CBase { function methodA() { print("methodA of CBase.") }; function methodB() { print("methodB of CBase.") }; } class CDerived extends CBase { hide function methodA() { print("Hiding methodA.") }; override function methodB() { print("Overriding methodB.") }; } var derivedInstance : CDerived = new CDerived; derivedInstance.methodA(); derivedInstance.methodB(); var baseInstance : CBase = derivedInstance; baseInstance.methodA(); baseInstance.methodB(); |
The output of this program shows that an override method overrides a base-class method.
В | Copy Code |
---|---|
Hiding methodA. Overriding methodB. methodA of CBase. Overriding methodB. |
Requirements
See Also
Reference
hide Modifiervar Statement
function Statement
class Statement
Concepts
Scope of Variables and ConstantsType Annotation