MATLAB Object-Oriented Programming

(Joyce) #1
classdef Sub < Super
...
methods (Access = protected)
function step1(obj)
% Subclass version
end
function step2(obj)
% Subclass version
end
function step3(obj)
% Subclass version
end
...
end
end

Override Superclass Methods


You can completely redefine a superclass method in a subclass. In this case, both the
superclass and the subclass would define a method with the same name. However, the
implementation would be different and the subclass method would not call the superclass
method.

classdef Super
methods
function foo(obj)
% Superclass implementation
end
end
end

classdef Sub < Super
methods
function foo(obj)
% Subclass implementation
end
end
end

12 How to Build on Other Classes

Free download pdf