Previous Page | Next Page

SAS Component Language Dictionary

SUPER



Invokes the inherited definition of a method
Category: Object Oriented

Syntax
Details
Examples
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
See Also

Syntax

CALL SUPER(object-id,method-name<,parameters>);
<return-value=>_SUPER<.method-name>(<parameters>);

object-id

contains the identifier of the object for which the method is invoked.

Type: Numeric or Object

method-name

is the name of the method to invoke.

Type: Character

parameters

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.  [cautionend]

Type: Numeric, Character

return-value

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


Example 1: Calling the Parent Method of an Overridden Method

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;


Example 2: Calling a Different Method in the Parent Class

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;


Example 3: Calling a Method in the Parent of a Parent Class

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:

  1. Method N in class S3 is invoked in DRS.SCL.

  2. In N, method M is invoked in class S2 via _SUPER. The parameter is -10 .

  3. Method M, which is within S2, invokes method M in class S via _SUPER. The parameter is 1 .

  4. In S, 1 is added to 199 and returned to S2.

  5. In S2, 200 is added to -10 and returned to S3.

  6. In S3, 190 is returned to DRS.SCL.


See Also

APPLY

INSTANCE

METHOD

NOTIFY

SEND

SUPAPPLY

Previous Page | Next Page | Top of Page