Reputation: 8759
I have a simple class structure like so:
classdef super < hgsetget
properties(Constant = true, Access = private)
PROP1 = 1;
PROP2 = {2 [3 4] [5 6]};
end
methods
function self = super()
// Constructor code here
// ...
end
end
end
which is then inherited by a subclass like so.
classdef sub < super
properties
PROP3 = 7;
end
methods
function self = sub()
// Subclass constructor here
// ...
self = self@super();
test = self.PROP1; // I don't appear to have access to PROP1 from Super
end
end
end
My issue is when I try to access to the super's property PROP1
or PROP2
I don't seem to get access:
No appropriate method, property, or field PROP1 for class sub.
Is there a way to access to the super's property within Matlab?
Upvotes: 3
Views: 2401
Reputation: 5978
In superclass super
set properties attributes to
properties(Constant = true, Access = protected)
From the documentation an access attribute determines what code can access these properties:
Upvotes: 7
Reputation: 124543
You define the properties as private
, those are not inherited.
Use Access = protected
instead.
Upvotes: 2