Why are implicit superclass constructor calls made in the wrong order in MATLAB 7.6 (R2008a)?

1 view (last 30 days)
I have definied a handle class, class_a, which is a superclass of class_b. In turn, class_b is a superclass of class_c. All of the class constructors do not require input parameters, and are being called implicitly. I expect the constructors to be called in the order
class_a
class_b
class_c
similar to other object oriented programming languages. However, they are actually called in the order:
class_c
class_b
class_a

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 12 Aug 2009
This change has been incorporated into the documentation in MATLAB 7.8 (R2009a). For previous releases, read below for any additional information:
This is the expected behavior of the class system in MATLAB 7.6 (R2008a), however it is not clearly documented.
MATLAB first calls the most specific class (class_c) constructor which gets a chance to control how superclass constructors are called. If there is no explicit call to a superclass constructor, the call is made before the object is accessed. This gives a constructor a chance to process input arguments and do any setup before calling superclass constructors. This process is repeated recursively when the superclass constructors are called.
To control the order in which superclass constructors are called, you can call them explicitly.

More Answers (0)

Tags

Products


Release

R2008a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!