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

Method scoping within a class hierarchy

A class can access all of the PUBLIC and PROTECTED methods of its super class as well as any methods that it defines. A super class that, in turn, inherits from another class inherits all its super class's PUBLIC and PROTECTED methods and so on up to the root of the hierarchy. Therefore when a class inherits all of the PUBLIC and PROTECTED methods of its super class, it inherits all of the PUBLIC and PROTECTED methods available all the way to the top of the class hierarchy.
While a subclass can access the PUBLIC and PROTECTED methods of any of its super classes, the reverse is not true for instance methods. You cannot invoke instance methods within a class that are defined only by a subclass of that class. Methods first defined in a subclass are simply not visible to any of its super classes, even though the subclass exists in the same class hierarchy as its super classes for a given object. Likewise, methods defined as PRIVATE in a super class are not visible to its subclasses. Because the default access mode for methods is PUBLIC, a method is always accessible to a subclass unless you specifically define it as PRIVATE. Therefore, a key benefit of classes is the PROTECTED access mode, which allows you to define an interrelated set of method definitions that are accessible within a class hierarchy, but which are invisible to any procedures or other classes that are outside that class hierarchy.
Note that an instance can call a PROTECTED method of a second instance that is at the same level or in a super class in the class hierarchy, and an instance can call a PRIVATE method of another instance if both are the same class.
* Comparison with procedure-based programming