Hello everyone, i am new to the OOP in Matlab.
I have a superclass A
classdef A properties Property1 end methods function obj = A() obj.Property1 = {}; end function add(obj,inputArg) obj.Property1{length(obj.Property1) + 1}=inputArg; end function str=output(obj) str=""; for i=1:length(obj.Property1) str=strcat(str," - ",string(obj.Property1{i}),newline); end end endend
and a subclass B
classdef B < A methods function obj = B() obj.add('Start'); end function outputArg = format(obj) outputArg = strcat("List:",newline,obj.output()); end endend
Now I run the following test code:
x=B();x.add('End');fprintf(x.format());
The result is
List:
although I expected
List: - Start - End
. What have I done wrong?
Thanks a lot
Stephan
Best Answer