In MATLAB, you can call the superclass constructor with the super
keyword followed by parentheses containing any inputs that the superclass constructor requires.
Here's an example of how to do it:
main.m342 chars16 lines
In this example, we assume SuperClass
has one input in the constructor. We pass that input to the superclass constructor using obj@SuperClass(input1)
. Then we continue with the ChildClass
constructor.
Note that if the superclass has a default constructor (constructor with no inputs), MATLAB will call it automatically and you don't have to call it explicitly in the subclass.
gistlibby LogSnag