Try OpenEdge Now
skip to main content
Object-oriented Programming
Designing Objects: Inheritance, Polymorphism, and Delegation : Class hierarchies and inheritance : Overriding methods within a class hierarchy
 

Overriding methods within a class hierarchy

A class definition (subclass) that inherits from another class can define a method to override a PUBLIC or PROTECTED method in its class hierarchy as long as it is not marked FINAL. The method must have a compatible access mode and the same method name, scope, return type, and number of parameters, and each corresponding parameter must be of the same mode (INPUT, OUTPUT, or INPUT-OUTPUT) and of the same data type as the method it is overriding. A compatible access mode means that the overriding method can have a less restrictive access mode than the overridden method. For example, a PUBLIC subclass method can override a PROTECTED super class method. The same scope means the methods must both be instance methods or both be static methods. The overriding method must also use the OVERRIDE keyword to assure the compiler that the override is intended. The method that is overridden does not need to be in the immediate super class. If ABL does not find a matching method in the immediate super class in the hierarchy, it searches further up the hierarchy. If no matching method is found in the hierarchy, ABL returns a compile-time error.
Note: The remainder of this section describes how overriding works for instance methods. For information on how overriding works for static methods, see Calling overridden and super-class static methods.
Once a method has been overridden, all calls to that method invoke the method in the most derived subclass where it is overridden. This is true whether the method is called from outside (using an object reference) or from inside the class hierarchy of the object. Thus, you can call any accessible method, whether it is abstract or implemented at the point of invocation. For more information on calling methods inside and outside of a class hierarchy, see Callingclass-based methods.
Note that you must override and implement any abstract methods in a non-abstract subclass that inherits them. However, if the inheriting subclass is abstract, you can, at your option, override any inherited abstract method and designate it again as abstract. The only difference you can make in creating a new abstract method definition is to specify a less restrictive access mode, overriding a protected abstract method to make it public. Note, also, that unlike an implemented property, you can override an implemented method and make it abstract as long as the inheriting subclass is also abstract.