classdef MySub < MySuperClass
methods
function disp(obj)
disp@MySuperClass(obj)
...
end
end
end
How to Call Superclass Constructor
If you create a subclass object, MATLAB calls the superclass constructor to initialize the
superclass part of the subclass object. By default, MATLAB calls the superclass
constructor without arguments. If you want the superclass constructor called with
specific arguments, explicitly call the superclass constructor from the subclass
constructor. The call to the superclass constructor must come before any other references
to the object.
The syntax for calling the superclass constructor uses an @ symbol:
Object returned
from superclass
Object being
constructed
obj = objobj = obj@@MySuMySuper Class(SuperClasper Class(SuperClassArgsArguments);uments);
Name of superclass
Superclass constructor
arugment list
In the following class, the MySub object is initialized by the MySuperClass constructor.
The superclass constructor constructs the MySuperClass part of the object using the
specified arguments.
classdef MySub < MySuperClass
methods
function obj = MySub(arg1,arg2,...)
obj = obj@MySuperClass(SuperClassArguments);
...
5 Class Definition—Syntax Reference