Contents | Prev | Next | Index


Instances and References

Instances of a classs type are dynamically allocated blocks of memory with a layout defined by the class type. They are also commonly refered to as objects. Objects are created using constructors, and can be explicitly destroyed using destructors. This is usually done via the standard procedures NEW or DISPOSE. Standard procedure NEW can take a constructor call as a second actual parameter. Each object of a class type has a unique copy of the fields declared in the class type. However, fields declared with the JAVA STATIC modifier are shared by all objects. Objects also share the same methods.

A variable of a class type contains a reference to an object of the class type. The variable doesn't contain the object itself, but rather is a pointer to a memory block that has been allocated for the object. Like pointer variables, multiple class type variables can refer to the same object. Furthermore, a class type variable can also contain the value NIL, indicating that it doesn't currently reference an object.

No explicit dereference of a class type variable is needed in order to gain access to its class members or to the referenced object. Unlike in the case of pointer variables, where it is necessary to use the ^ operator (e.g. Ptr^.Field) to access a field in a dynamically allocated record, the ^ operator is implied when accessing a member of an object and the syntax is simply Instance.Field. This documentation uses the term object reference to denote the value of a class type. For example, a class-type variable contains an object reference.


Contents | Prev | Next | Index

Canterbury Pascal for JVM  (Last documentation update Sep 02, 2004)
Copyright © 1999-2004 J.Neuhoff - mhccorp.com  . All rights reserved.
Please send any comments or corrections to neuhoff@mhccorp.com