User`s manual

Creating and Using Java Objects
5-17
Accessing Data from a Static Field
In Java, a static data field is a field that applies to an entire class of objects.
Static fields are most commonly accessed in relation to the class name itself in
Java. For example, the code below accesses the
WIDTH field of the Frame class
by referring to it in relation to the package and class names,
java.awt.Frame,
rather than an object instance.
width = java.awt.Frame.WIDTH;
In MATLAB, you can use that same syntax. Or you can refer to the WIDTH field
in relation to an instance of the class. The example shown here creates an
instance of
java.awt.Frame called frameObj, and then accesses the WIDTH field
using the name
frameObj rather than the package and class names.
frame = java.awt.Frame('Frame A');
width = frame.WIDTH
width =
1
Assigning to a Static Field
You can assign values to static Java fields by using a static set method of the
class, or by making the assignment in reference to an instance of the class. For
more information, see the previous section, “Accessing Data from a Static
Field”. You can assign
value to the field staticFieldName in the example
below by referring to this field in reference to an instance of the class.
objectName = java.className;
objectName.staticFieldName = value;
Note MATLAB does not allow assignment to static fields using the class
name itself.
Determining the Class of an Object
To find the class of a Java object, use the query form of the MATLAB function,
class. After execution of the following example, frameClass contains the name
of the package and class that Java object
frame instantiates.