This documentation is archived and is not being maintained.
super Statement
Visual Studio 2010
Refers to the base object of the current object. This can be used in two contexts.
// Syntax 1: Calls the base-class constructor with arguments. super(arguments) // Syntax 2: Accesses a member of the base class. super.member
In the following example, super refers to the constructor of the base class.
class baseClass {
function baseClass() {
print("Base class constructor with no parameters.");
}
function baseClass(i : int) {
print("Base class constructor. i is "+i);
}
}
class derivedClass extends baseClass {
function derivedClass() {
// The super constructor with no arguments is implicitly called here.
print("This is the derived class constructor.");
}
function derivedClass(i : int) {
super(i);
print("This is the derived class constructor.");
}
}
new derivedClass;
new derivedClass(42);
This program displays the following output when run.
Base class constructor with no parameters. This is the derived class constructor. Base class constructor. i is 42 This is the derived class constructor.
In the following example, super allows access to an overridden member of the base class.
class baseClass {
function test() {
print("This is the base class test.");
}
}
class derivedClass extends baseClass {
function test() {
print("This is the derived class test.");
super.test(); // Call the base class test.
}
}
var obj : derivedClass = new derivedClass;
obj.test();
This program displays the following output when run.
This is the derived class test. This is the base class test.
Show: