Class Attributes

Table of Class Attributes

All classes support the attributes listed in the following table. Attributes enable you to modify the behavior of class. Attribute values apply to the class defined within the classdef block.

classdef (Attribute1 = value1, Attribute2 = value2,...) ClassName
   ...
end

For more information on attribute syntax, see Specifying Attributes.

Attribute Name

Class

Description

Abstract

logical

(default = false)

If specified as true, this class is an abstract class (cannot be instantiated).

See Defining Abstract Classes for more information.

AllowedSubclasses

meta.class object or cell array of meta.class objects

List classes that can subclass this class. Specify subclasses as meta.class objects in the form:

  • A single meta.class object

  • A cell array of meta.class objects. An empty cell array, {}, is the same as a Sealed class (no subclasses).

Specify meta.class objects using the ?ClassName syntax only.

See Controlling Allowed Subclasses for more information.

ConstructOnLoad

logical

(default = false)

If true, MATLAB® calls the class constructor when loading an object from a MAT-file. Therefore, you must implement the constructor so it can be called with no arguments without producing an error.

See Calling Constructor When Loading

HandleCompatible

logical

(default = false)for value classes

If specified as true, this class can be used as a superclass for handle classes. All handle classes are HandleCompatible by definition. See Supporting Both Handle and Value Subclasses for more information.

Hidden

logical

(default = false)

If true, this class does not appear in the output of the superclasses or help functions.

InferiorClasses

meta.class object or cell array of meta.class objects

Use this attribute to establish a precedence relationship among classes. Specify a cell array of meta.class objects using the ? operator.

The fundamental classes are always inferior to user-defined classes and do not show up in this list.

See Class Precedence and Dominant Argument in Overloaded Plotting Functions.

Sealed

logical

(default = false)

If true, this class can not be subclassed.

Specifying Attributes

Attributes are specified for class members in the classdef, properties, methods, and events definition blocks. The particular attribute setting applies to all members defined within that particular block. This means that, for example, you might use multiple properties definition blocks so you can apply different attribute setting to different properties.

Superclass Attributes Are Not Inherited

Class attributes are not inherited, so superclass attributes do not affect subclasses.

Attribute Syntax

Specify class attribute values in parentheses, separating each attribute name/attribute value pair with a comma. The attribute list always follows the classdef or class member key word, as shown below:

classdef (attribute-name = expression, ...) ClassName

   properties (attribute-name = expression, ...)
      ...
   end
   methods (attribute-name = expression, ...)
      ...
   end
   events (attribute-name = expression, ...)
      ...
   end
end

See Expressions in Attribute Specifications for more information.

Was this topic helpful?