Perhaps you noticed that none of the qualified-identifier definitions in this book include any access-control modifiers (public, internal, protected, or private). We've seen plenty of this:
fruit var orange:String = "Round citrus fruit";
But none of this (note the addition of the access-control modifier private):
private fruit var orange:String = "Round citrus fruit";
And for good reason: it is illegal to use access-control modifiers with definitions that include a qualifier namespace. For example, the following code:
private fruit var orange:String;
yields the error:
Access specifiers not allowed with namespace attributes
But if access-control modifiers are illegal, then what governs the accessibility of a qualified identifier? Answer: the accessibility of the identifier's qualifier namespace.
The accessibility of the qualifier namespace in a qualified identifier determines that identifier's accessibility. If the qualifier namespace is visible in a given scope, then the qualified identifier is also visible.
For example, in the expression
gameitems.fruit::orange, the variable
fruit::orange is accessible if and
only if the namespace
accessible in the scope where the expression occurs. The accessibility
of the variable
entirely determined by the accessibility of the namespace
Example 17-2 demonstrates qualified identifier visibility with generic code.
Example 17-2. Qualified identifier visibility demonstration
// Create namespace ...