Level 4 — Classes
Fields
Original notes by SunDiaL · View English source
A field is just a class variable.
Defining a field
You do it just as you would do a variable, except it within the scope of the class.
class ExampleClass
{
public int x;
}
Using a field
You do is just as you would do a variable, except you have to go through an instance of your class to do so.
class Program
{
public void main()
{
ExampleClass ex = new ExampleClass();
ex.x = 5;
}
}