May 27, 2002 - Using Qualified Names
![]() |
May 27, 2002 Using Qualified Names Tips: May 2002
Yehuda Shiran, Ph.D.
|
package USA {
class Head {
static var President : String = "Bush";
}
};
package UK {
public class Head {
static var PrimeMinister : String = "Blair";
}
public class Localization {
static var Currency : String = "Pound";
}
};
package USA.Florida {
public class Head {
static var Governor : String = "Bush";
}
};
Let's declare a local class now:
class Head {
static var Governor : String = "Davis";
}
Let's import the three databases from above:
import USA;
import UK;
import USA.Florida;
And then let's print some class members:
print(Head.Governor);
print(USA.Head.President);
print(UK.Head.PrimeMinister);
print(USA.Florida.Head.Governor);
print(Localization.Currency);
print(UK.Localization.Currency);
Here is the output of the above code:
Davis
Bush
Blair
Bush
Pound
Pound
Notice that when the class location is ambiguous, you must use fully-qualified names. The class Head, for example, appears in USA, UK, USA.Florida, and locally, so the namespace must prefix this class. The class Localization, however, appears only in the UK namespace, so there is no need to use the fully-qualified variable names.To learn more about JScript .NET, go to Column 109, JScript .NET, Part III: Classes and Namespaces.


Find a programming school near you