Field (computer science): Difference between revisions
added requested clarification |
→Java Field modifiers: added C# field modifiers |
||
Line 7: | Line 7: | ||
In [[object-oriented programming]], ''field'' (also called ''data member'') is the [[data]] [[information hiding|encapsulated]] within a [[class (computer science)|class]] or [[object (object-oriented programming)|object]]. In the case of a regular field (also called ''instance variable''), for each instance of the object there is an instance variable: for example, an Employee class has a Name field and there is one distinct name per employee. A static field (also called ''class variable'') is one variable, which is shared by all instances. |
In [[object-oriented programming]], ''field'' (also called ''data member'') is the [[data]] [[information hiding|encapsulated]] within a [[class (computer science)|class]] or [[object (object-oriented programming)|object]]. In the case of a regular field (also called ''instance variable''), for each instance of the object there is an instance variable: for example, an Employee class has a Name field and there is one distinct name per employee. A static field (also called ''class variable'') is one variable, which is shared by all instances. |
||
== |
==Field modifiers in some object-oriented languages== |
||
{| border="2" cellpadding="4" cellspacing="0" style="margin: 1em 1em 1em 0; background: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse; font-size: 95%;" |
{| border="2" cellpadding="4" cellspacing="0" style="margin: 1em 1em 1em 0; background: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse; font-size: 95%;" |
||
|- bgcolor="#CCCCCC" align="center" |
|- bgcolor="#CCCCCC" align="center" |
||
Line 19: | Line 19: | ||
|- |
|- |
||
| || <code>volatile</code> |
| || <code>volatile</code> |
||
|} |
|||
==C# Field modifiers== |
|||
{| border="2" cellpadding="4" cellspacing="0" style="margin: 1em 1em 1em 0; background: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse; font-size: 95%;" |
|||
|- bgcolor="#CCCCCC" align="center" |
|||
! Access Modifier !! Field Modifier |
|||
|- |
|||
| <code>public</code> || <code>sealed</code> |
|||
|- |
|||
| <code>private</code> || <code>static</code> |
|||
|- |
|||
| <code>protected</code> || <code>volatile</code> |
|||
|- |
|||
| <code>internal</code> || |
|||
|- |
|||
| <code>protected internal</code> || |
|||
|} |
|} |
||
Revision as of 21:50, 6 July 2008
In computer science, data that has several parts can be divided into fields. For example, a computer may represent today's date as three distinct fields: the day, the month and the year.
Programming languages usually have a record data type to represent composite data types as a series of fields. An array of boolean values can be represented as a bit field.
Relational databases arrange data as sets of database records, also called rows. Each record consists of several fields; the fields of all records form the columns.
In object-oriented programming, field (also called data member) is the data encapsulated within a class or object. In the case of a regular field (also called instance variable), for each instance of the object there is an instance variable: for example, an Employee class has a Name field and there is one distinct name per employee. A static field (also called class variable) is one variable, which is shared by all instances.
Field modifiers in some object-oriented languages
Access Modifier | Field Modifier |
---|---|
public |
final
|
private |
static
|
protected |
transient
|
volatile
|
C# Field modifiers
Access Modifier | Field Modifier |
---|---|
public |
sealed
|
private |
static
|
protected |
volatile
|
internal |
|
protected internal |
It must be noted that improper usage of modifiers of fields may result in unstable software behaviour.