Referring to members of the outer class
Within the inner class, you refer to methods, fields, and properties on the outer class by
using the outer keyword followed by a period, followed by the property name.
The following example has an inner class that refers to a field on the outer class:
package example
class Greeting {
// Field in the main (outer) class
public var intro : String = "I would like to say"
// Function in the main (outer) class
public function greet() {
var x = new FrenchGreeting()
print(x.sayWhat())
}
// INNER CLASS DECLARATION
public class FrenchGreeting {
public function sayWhat() : String {
return outer.intro + " " + "bonjour"
}
}
}
If there is no ambiguity about the variable to which a name refers, the outer keyword and the
following period are optional:
return intro + " " + "bonjour"
