Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

override Modifier

Declares that a method or property overrides a method or property in a base class.

override statement
statement

Required. A method or property definition.

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.

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.

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.

Hiding methodA.
Overriding methodB.
methodA of CBase.
Overriding methodB.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.