|Example 1: Calling the Parent Method of an Overridden Method|
|Example 2: Calling a Different Method in the Parent Class|
|Example 3: Calling a Method in the Parent of a Parent Class|
Type: Numeric or Object
Note: These parameters are update parameters. See
Input, Output, and Update Parameters for more information.
Type: Numeric, Character
Type: Numeric, Character, List, Object-name, Class, or Interface
SUPER provides a convenient way of calling a method in the parent class from a method in the child class. In particular, it is useful for calling the corresponding parent method from an overridden method in the child.
Although method-name is typically the name of the currently executing method, which is stored in the system variable _METHOD_, any other method name can be used.
The object identified by object-id must be the same object whose method is currently executing. The identifier for this object is stored in the system variable _SELF_.
For more information about system variables, see System Variables.
SUPER can also be used with CLASS blocks, USECLASS blocks and dot notation by using _SUPER. If you are specifying the same method in the parent and child classes, you do not need to specify the method name.
In this example, _SUPER is used to call the parent method of an overridden method in class X.
Y.SCL class y; m: method; ...SCL statements... endmethod; endclass; X.SCL class x extends y; m: method; _super(); /* _super invokes method M in class Y */ endmethod; endclass;
To call a different method in the parent class, specify the method name after _SUPER using dot notation. The following example invokes the M2 method in class Y using _SUPER:
Y.SCL class y; m2: method; ...SCL statements... endmethod; endclass; X.SCL class x extends y; m: method; _super.m2(); endmethod; endclass;
This example demonstrates how you can use inheritance to invoke a method in the parent of a parent class.
S.SCL class s; m: method n: num return=num; dcl num x; x=n+199; return x; endmethod; endclass; S2.SCL class s2 extends s; m: method n: num return=num/(state='O'); dcl num x; x=n+_super(1); return x; endmethod; endclass; S3.SCL class s3 extends s2; n: method return=num; dcl num x; x=_super.m(-10); return x; endmethod; endclass; DRS.SCL init: dcl s3 sobj=_new_ s3(); dcl num x; dcl string s; x=sobj.n(); put x=; return;
This example results in the following output:
The calling sequence for the above example is as follows:
1is added to
199and returned to S2.
200is added to
-10and returned to S3.
190is returned to DRS.SCL.
Top of Page
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.