2
2
.
.
4
4
.
.
3
3
F
F
i
i
e
e
l
l
d
d
s
s
I
I
n
n
f
f
o
o
Field is a Constant or Variable declared inside a Class or Object
public Fields can be referenced inside and outside of the Class or Object (by behaviour)
private Fields can be referenced only inside the Class or Object (from Class Fields, Properties, Methods)
Use this to reference Fields from within Class (Fields, Properties, Methods).
Fields
//===========================================================================================================
// CLASS: Person
//===========================================================================================================
class Person {
//DECLARE FIELD.
public var name : String = ""
//CONSTRUCTOR.
constructor(name: String) { this.name = name } //Use this to reference Field
}
//===========================================================================================================
// FUNCTION: main
//===========================================================================================================
fun main() {
//CREATE OBJECT.
var john = Person("John")
john.name = "Bill" //Set Field
var greet = john.name //Read Field
//DISPLAY.
print(greet) //Bill
}