June 14, 2002 - Using override
![]() |
June 14, 2002 Using override Tips: June 2002
Yehuda Shiran, Ph.D.
|
override behavior. The class FirstBase has two methods: pitcher() and hitter(), each printing a unique message:
class FirstBase {
function pitcher() { print("I am a pitcher on first base"); }
function hitter() { print("I am a hitter on first base"); }
}
Let's define a derived class now. It redefines both the pitcher() and the hitter() methods. The pitcher() method will be marked as hide, and the hitter() function will be marked as override:
class SecondBase extends FirstBase {
hide function pitcher() { print("I am a pitcher on second base"); }
override function hitter() { print("I am a hitter on second base"); }
}
Let's create an instance of the derived class, SecondBase:
player : SecondBase = new SecondBase;
and call his pitcher() and hitter() methods:
player.pitcher();
player.hitter();
The output should reflect the default of overriding the base methods:
I am a pitcher on second base
I am a hitter on second base
To learn more about JScript .NET, go to Column 110, JScript .NET, Part IV: Inheritance.


Find a programming school near you