Call instance methods from outside a class hierarchy where they are defined
- Last Updated: October 30, 2020
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
Call instance methods from outside a class hierarchy where they are defined
Syntax
You can access PUBLIC instance methods from outside the class hierarchy of a
given object by using an object reference to qualify the method name. When you invoke a
PUBLIC method on an object that is overridden in the
object’s class hierarchy, the AVM invokes the method in the most derived subclass that
defines the method. A PACKAGE-PRIVATE method can be called from within the
class and any class within its package. A PACKAGE-PROTECTED method can be
called from within the class, any class within its package, and from within any subclass
that inherits the class. There is no access to PRIVATE or
PROTECTED methods from outside the class hierarchy.
This is the syntax to invoke a method from outside a class instance:
|
Element descriptions for this syntax diagram follow:
- return-variable
- If the method returns a value that is assigned, the name of the variable to put the return value into.
- object-reference
- An object reference whose class or interface type defines the method you are calling.
- method-name
- The name of a
PUBLICmethod defined somewhere in the class hierarchy of object-reference. - [ parameter [ , parameter]...]
- The parameters, if any, of the method. For more information on the syntax of parameter, see the Parameter passing syntax reference entry in ABL Reference.
- NO-ERROR
- Optionally redirects error processing when the method is called as a statement.
The following example shows
two sample classes, where a method in acme.myObjs.CustObj calls
the public Alert( ) and InfoMsg( ) methods
in an instance of acme.myObjs.Common.MsgObj that
is created for the CustObj class:
|
In this case, rMsg is a private object reference data member that is
initialized to an instance of MsgObj that is instantiated and returned from
the MessageHandler( ) method of the CommonObj super class.
(See the listing for this super class in Call methods from inside a class hierarchy where they are defined).
This MsgObj instance
holds error and general message information specifically for the CustObj class that
can be accessed using the Alert( ) and InfoMsg( ) methods
implemented as follows:
|