Modify Inherited Properties
In this section...
“Superclass Property Modification” on page 12-20
“Private Local Property Takes Precedence in Method” on page 12-20
Superclass Property Modification
There are two separate conditions under which you can redefine superclass properties:
- The value of the superclass property Abstract attribute is true
- The values of the superclass property SetAccess and GetAccess attributes are
private
If a superclass defines a property as abstract, the subclass must implement a concrete
version of this property or the subclass is also abstract. Superclasses define abstract
properties to create a consistent interface among subclasses.
If a superclass defines a property with private access, then only the superclass can access
this property. The subclass can implement a different property with the same name.
Private Local Property Takes Precedence in Method
When superclass and subclass define a property with the same name, methods that refer
to this property access the property of the class defining the method.
For example, if a subclass property has the same name as a superclass private property,
and a method of the superclass references the property name, MATLAB accesses the
property defined by the superclass.
Consider the following classes, Super and Sub:
classdef Super
properties (Access = private)
Prop = 2
end
methods
function p = superMethod(obj)
p = obj.Prop;
12 How to Build on Other Classes