Skip to main content

Multiple Inheritance

Multiple Inheritance

A class can inherit its behavior and class type from more than one superclass. To establish multiple inheritance, list multiple superclasses within parentheses. The leftmost superclass is the primary superclass and specifies all the class keyword values.

For example, if class X inherits from classes A, B, and C, its definition includes:

Class X Extends (A, B, C) 
{
}

The default inheritance order for the class compiler is from left to right, which means that differences in member definitions among superclasses are resolved in favor of the leftmost superclass (in this case, A superseding B and C, and B superseding C.)

Specifically, for class X, the values of the class parameter values, properties, and methods are inherited from class A (the first superclass listed), then from class B, and, finally, from class C. X also inherits any class members from B that A has not defined, and any class members from C that neither A nor B has defined. If class B has a class member with the same name as a member already inherited from A, then X uses the value from A; similarly, if C has a member with the same name as one inherited from either A or B, the order of precedence is A, then B, then C.

InterSystems recommends using left inheritance in all new programming, but you can specify the Inheritance keyword to override this. For reasons of history, most InterSystems IRIS classes contain Inheritance = right.

FeedbackOpens in a new tab