Information Technology Reference
In-Depth Information
Class Members
Fields and methods are the most important of the class member types. Fields are data mem-
bers and methods are function members.
Fields
A field is a variable that belongs to a class.
￿
It can be of any type, either predefined or user-defined.
￿
Like all variables, fields store data, and have the following characteristics:
- They can be written to.
-They can be read from.
The minimum syntax for declaring a field is the following:
Type
Type Identifier ;
Field name
For example, the following class contains the declaration of field MyField , which can store
an int value:
class MyClass
{ Type
int MyField;
} Field name
Note Unlike C and C++, there are no global variables (i.e., variables or fields) declared outside of a type.
All fields belong to a type, and must be declared within the type declaration.
Search WWH ::




Custom Search