SAS Component Language Dictionary |
Category: | Object Oriented |
Syntax |
CALL SUPER(object-id,method-name<,parameters>); |
<return-value=>_SUPER<.method-name>(<parameters>); |
contains the identifier of the object for which the method is invoked.
are additional numeric or character arguments that are required by the method. Use commas to separate multiple options.
Note: These parameters are update parameters. See Input, Output, and Update Parameters for more information.
contains the value returned by the inherited method.
Type: Numeric, Character, List, Object-name, Class, or Interface
Details |
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.
Examples |
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:
x=190
The calling sequence for the above example is as follows:
In N, method M is invoked in class S2 via _SUPER. The parameter is -10 .
Method M, which is within S2, invokes method M in class S via _SUPER. The parameter is 1 .
See Also |
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.