Monday, March 9, 2009

Using Package Members  

0 comments

To use a public package member from outside its package, you must do one of the following: 

  • Refer to the member by its fully qualified name 
  • Import the package member 
  • Import the member's entire package 

Each is appropriate for different situations, as explained in the sections that follow.

So far, most of the examples in this tutorial have referred to types by their simple names, such as Rectangle and StackOfInts. You can use a package member's simple name if the code you are writing is in the same package as that member or if that member has been imported. 

However, if you are trying to use a member from a different package and that package has not been imported, you must use the member's fully qualified name, which includes the package name. Here is the fully qualified name for the Rectangle class declared in the graphics package in the previous example. 


                              graphics.Rectangle

Importing a Package Member

Here's how you would import the Rectangle class from the graphics package created in the previous section.

                 import graphics.Rectangle;

Importing an Entire Package

To import all the types contained in a particular package, use the import statement with the asterisk (*) wildcard character. 

                              import graphics.*;






What next?

You can also bookmark this post using your favorite bookmarking service:

Related Posts by Categories



0 comments: to “ Using Package Members

Extension Factory Builder