Thursday, April 21, 2011

Field values

Properties are sometimes called variables or states or data members of the class. To declare a property use the following syntax:

[ "public" | "private" | "protected" ] [ "final" ]
[ "static" | "transient" | "volatile" ]
  data_type var_name [=var_initializer ] ";"

The items in the first optional group indicate the visibility or accessibility from other objects. public means visible everywhere (global). private indicates accessible only to this class and nested classes. protected means visible to this class or inherited (ie. extended) classes only. The default (keyword omitted) is friendly or visible within the current package (folder) only.
final indicates continuous retention and unchangeable after initial assignment (ie. it is read only or constant).
The third optional group indicates how long a value is retained in the variable. static indicates that the value is shared by all members of the class and exists for all runtime. Static properties can be referenced without creating an instance of the class. transient prevents the variable from being transferred during a serial operation such as file i/o. volatile is used in multi-threading to prevent overwrite issues.

No comments:

Post a Comment

Chitika