METHOD-ID paragraph
The METHOD-ID paragraph specifies the name by which a method is known and assigns selected attributes to that method. The METHOD-ID paragraph is required and must be the first paragraph in a method identification division.
- method-name-1
- An alphanumeric literal or national literal that contains the name of the method. The name must conform to the rules of formation for a Java™ method name. Method names are used directly, without translation. The method name is processed in a case-sensitive manner.
Method signature
The signature of a method consists of the name of the method and the number and types of the formal parameters to the method as specified in the PROCEDURE DIVISION USING phrase.
Method overloading, overriding, and hiding
COBOL methods can be overloaded, overridden, or hidden, based on the rules of the Java language.
- Method overloading
- Method names that are defined
for a class are not required to be unique. (The set of methods defined
for a class includes the methods introduced by the class definition
and the methods inherited from parent classes.)
Method names defined for a class must have unique signatures. Two methods defined for a class and that have the same name but different signatures are said to be overloaded.
The type of the method return value, if any, is not included in the method signature.
A class must not define two methods with the same signature but different return value types, or with the same signature but where one method specifies a return value and the other does not.
The rules for overloaded method definitions and resolution of overloaded method invocations are based on the corresponding rules for Java.
- Method overriding (for instance methods)
An instance method in a subclass overrides an instance method with the same name that is inherited from a parent class if the two methods have the same signature.
When a method overrides an instance method defined in a parent class, the presence or absence of a method return value (the PROCEDURE DIVISION RETURNING data-name) must be consistent in the two methods. Further, when method return values are specified, the return values in the overridden method and the overriding method must have identical data types.
An instance method must not override a factory method in a COBOL parent class, or a static method in a Java parent class.
- Method hiding (for factory methods)
A factory method is said to hide any and all methods with the same signature in the superclasses of the method definition that would otherwise be accessible. A factory method must not hide an instance method.