MainframeMaster

COBOL Tutorial

SUPER - Call Parent Method

Progress0 of 0 lessons

Overview

Use SUPER inside an overridden method to invoke the parent implementation, then add/alter behavior.

🧱 Analogy

Building an extension on a house: you rely on the existing foundation (SUPER) and add rooms.

Override and Call SUPER

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CLASS-ID. BASE. METHOD-ID. CALC TOTAL PUBLIC. PROCEDURE DIVISION USING AMT RETURNING RES. MOVE AMT TO RES EXIT METHOD. END METHOD CALC. END CLASS BASE. CLASS-ID. DERIVED INHERITS FROM BASE. METHOD-ID. CALC OVERRIDE. PROCEDURE DIVISION USING AMT RETURNING RES. INVOKE SUPER "CALC" USING AMT RETURNING RES ADD 10 TO RES EXIT METHOD. END METHOD CALC.

Signature must match; call SUPER first, then customize.

Best Practices and Pitfalls

Best Practices

  • Document whether SUPER must be called (before/after)
  • Keep overrides minimal and focused

Common Mistakes

MistakeProblemFix
Not calling SUPER when requiredViolates base class contractCall SUPER or re-implement contract
Changing signatureNot an overrideMatch parent signature

Quick Reference

ActionSyntaxExample
Call parentINVOKE SUPER "name"INVOKE SUPER "INIT"
OverrideMETHOD-ID. name OVERRIDEMETHOD-ID. CALC OVERRIDE

Test Your Knowledge

1. What does SUPER refer to?

  • Current object
  • Parent class implementation
  • Sibling object
  • Factory

2. How to call the parent method?

  • INVOKE SELF
  • INVOKE SUPER
  • CALL PARENT
  • DISPLAY SUPER

3. When to use SUPER?

  • Always
  • When you need base behavior plus extra logic
  • Never
  • Only in main program

Frequently Asked Questions