
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
240
|
Chapter 9: Packages
A reference to a class that includes its complete package name is known as a fully
qualified reference. By contrast, an unqualified reference includes just the class name.
For example, SpaceShip is an unqualified reference, while game.vehicles.SpaceShip is
a fully qualified reference.
Prior to discussing packages, we’ve used unqualified references when creating
instances of classes and specifying the datatypes of variables, parameters, and return
types. For example, if the class SpaceShip were not in a package, we would use the
following syntax to create a SpaceShip instance and store it in a typed variable:
var ship:SpaceShip = new SpaceShip( );
However, if a class is in a package, we must use a fully qualified reference when cre-
ating instances of the class and specifying the datatypes of variables, parameters, and
return types. Therefore, if the SpaceShip class were in the package game.vehicles,we
would use fully qualified references, such as:
var ship:game.vehicles.SpaceShip = new game.vehicles.SpaceShip( );
Similarly, when SpaceShip is not in a package, we specify the return type of a method
using
:SpaceShip, as in:
public function getClosestShip ( ):SpaceShip {
// Method body not shown...
}
However, if the SpaceShip class is in a package, such as game.vehicles ...