MATLAB: Do I get an error if do not define a constructor in the inherited class

constructorerrorinheritanceMATLABobject oriented programmingooptoo many input arguments

Here's a simple example that does not work in the MATLAB language:
classdef Bar < handle
% Bar class
properties
Value
end
methods
function self = Bar(value)
self.Value = value;
end
end
end
classdef Foo < Bar
% Foo class
% No has constructor. We want to use the "Bar" constructor
end
>> f = Foo(10)
Error using Foo
Too many input arguments.
Too many input arguments.???
Ok…
>> f = Foo()
Error using Bar (line 10)
Not enough input arguments.
Error in Foo (line 1)
classdef Foo < Bar
What's going on? This is the ordinary inheritance. I would not want every time to write this:
classdef Foo < Bar
methods
function self = Foo(value)
self = self@Bar(value);
end
end
end

Best Answer

Classes and subclasses do not need a constructor.
classdef mysimpleclass
end
is perfectly valid. If a subclass does not have a constructor it calls the superclass constructor with no arguments. In other words the default constructor looks something like
function obj = mysubclass()
obj = obj@myclass;
end
It sounds like you would like the default constructor to look like
function obj = mysubclass(varargin)
obj = obj@myclass(varargin{:});
end
such that it would pass the arguments up the chain. I think both are reasonable defaults. There is a slight difference between MATLAB and Python (and most other languages) which potentially swayed TMW to go with the former approach in which no arguments get passed to the superclass. Because everything is an array in MATLAB, and how TMW chose to implement the OO system, the constructor for every MATLAB class needs to support being called with no input arguments (this is well documented).
EDIT
I think the choice becomes clearer if expand from the no constructor case a little bit. Consider
classdef mysubclass < myclass
methods
function obj = mysubclass(varargin)
end
end
end
Calling the mysubclass constructor invisibly calls the myclass constructor with no arguments. I believe this is documented. As we are guaranteed that the myclass constructor can be called with no arguments, it makes a little more sense to pass it no arguments (which will not crash) than pass it all the arguments which might result in an error. Either way you will end up with having to explicitly call the superclass constructor sometimes (either to pass all arguments or to pass no/some arguments). Passing all arguments seems less robust than pass no arguments. Passing a subset just seems silly.