【发布时间】:2019-02-17 14:01:35
【问题描述】:
在 Matlab (2017a) 中,子类不能限制对在抽象超类中声明为抽象的继承方法的访问。为什么不允许这样做?一个小例子:
超级.m
classdef (Abstract) super
methods (Abstract)
out = fun(obj,in)
end
end
子.m
classdef sub < super
properties
prop
end
methods (Access='private') %remove the access restriction to run without errors
function out = fun(obj,in)
out = obj.prop * in;
end
end
end
testInheritance.m
instance = sub;
执行 testInheritance.m 会导致以下错误消息:
使用子类“sub”中的方法“fun”时出错使用不同的访问权限 权限高于其超类“super”。
【问题讨论】:
标签: matlab oop inheritance