Skip to Main Content Skip to Search
Product Documentation

Subclassing Multiple Classes

Class Member Compatibility

When you create a subclass derived from multiple classes, the subclass inherits the properties, methods, and events defined by all specified superclasses. If more than one superclass defines a property, method, or event having the same name, there must be an unambiguous resolution to the multiple definitions. You cannot derive a subclass from any two or more classes that define incompatible class members.

There are various situations where you can resolve name and definition conflicts, as described in the following sections.

Property Conflicts

If two or more superclasses define a property with the same name, then at least one of the following must be true:

Method Conflicts

If two or more superclasses define methods with the same name, then at least one of the following must be true:

Event Conflicts

If two or more superclasses define events with the same name, then at least one of the following must be true:

Using Multiple Inheritance

Resolving the potential conflicts involved when defining a subclass from multiple classes often reduces the value of this approach. For example, problems can arise when you enhance superclasses in future versions and introduce new conflicts.

Reduce potential problems by implementing only one unrestricted superclass. In all other superclasses, all methods are abstract and must be defined by a subclass or inherited from the unrestricted superclass.

In general, when using multiple inheritance, ensure that all superclasses remain free of conflicts in definition.

See Defining a Subclass for the syntax used to derive a subclass from multiple superclasses.

See Supporting Both Handle and Value Subclasses — Handle-Compatible Classes for techniques that provide greater flexibility when using multiple superclasses.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS