skip to main content

Object-oriented Programming : Other object oriented programming features : Parametric Polymorphism

Parametric Polymorphism
Method overloading provides the ability to declare two or more methods of the same name, but with a different number of parameters and types. Each method has a method resolution signature that consists of the method name and all of the relevant information from the definition of each of the parameters, and from the returning item. During the resolution of the method, the signature derived from the invocation is compared with all methods of the same name. If the signatures match exactly, that method is bound. If not, the method that most closely matches the signature while still conforming is bound.
No two methods within a class may have the same signature.
    Method-id. PrintIt.
    Linkage section.
    01  In-o                   usage object.
    Procedure division using In-o.
        invoke in-o "PrintMe".
    End Method.
    Method-id. PrintIt.
    Working-Storage section.
    01  Out-p                  pic ZZZ,ZZZ,ZZZ.
    Linkage section.
    01  In-p                   pic 9(9).
    Procedure division using In-p.
        move In-p to Out-p.
        display out-p.
    End Method.
    Method-id. PrintIt.
    Working-Storage section.
    01  Out-p                  pic $$$,$$$.99.
    Linkage section.
    01  In-p                   pic s9(5)v99 packed-decimal.
    Procedure division using In-p.
        move In-p to Out-p.
        display out-p.
    End Method.
    Method-id. PrintIt.
    Linkage section.
    01  In-x                   pic x(20).
    01  In-len                 pic 9(4).
    Procedure division using In-x, In-len.
        display in-x(1:in-len).
    End Method.
    Invoke aClass "PrintIt" using anObject.
    aClass:>PrintIt (anObject).
    Invoke aClass "PrintIt" using "FooBar"3.
    aClass:>PrintIt ("FooBar"3).
    Invoke aClass "PrintIt" using 32
    aClass:>PrintIt (32)

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left