while extending base class call super class constructor in matlab

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.m
classdef ChildClass < SuperClass
    properties
        % Declare properties here
    end
    
    methods
        function obj = ChildClass(input1, input2)
            % Call superclass constructor
            obj@SuperClass(input1);
            
            % Continue with child class constructor
            % ...
        end
    end
end
342 chars
16 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