Accessing an inner class from a class that extends the outer class

Classes that derive from the outer class can use the inner class.

The following code defines the Greeting class and its inner class FrenchGreeting.

package example

class Greeting {
  // 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 "Bonjour"
    }
  }
}
The following example subclasses the Greeting class and uses the method in the inner FrenchGreeting class:
package example

class OtherGreeting extends Greeting {
  public function greetme() {
    var f = new Greeting.FrenchGreeting()
    print(f.sayWhat())
  }
}

You can test this code by using the following code in the Gosu Scratchpad:

var t = new example.OtherGreeting()
t.greetme()

This code prints:

Bonjour