NAMES
Example: Access to
public
 and Non 
public
 Classes
6.6.4
and:
package points;
public class Point {
protected int x, y;
public void move(int dx, int dy) { x += dx; y += dy; }
public int getX() { return x; }
public int getY() { return y; }
}
which declare two class types in the package
points
:
The class type
PointVec
 is not
public
 and not part of the
public
 interface
of the package
points
, but rather can be used only by other classes in the
package.
The class type
Point
 is declared
public
 and is available to other packages. It
is part of the
public
 interface of the package
points
.
The methods
move
,
getX
, and
getY
 of the class
Point
 are declared
public
and so are available to any Java code that uses an object of type
Point
.
The fields
x
 and
y
 are declared
protected
 and are accessible outside the
package
points
 only in subclasses of class
Point,
 and only when they are
fields of objects that are being implemented by the code that is accessing
them.
See  6.6.7 for an example of how the
protected
 access modifier limits access.
6.6.4   Example: Access to
public
 and Non 
public
 Classes
If a class lacks the
public
 modifier, access to the class declaration is limited to
the package in which it is declared ( 6.6). In the example:
package points;
public class Point {
public int x, y;
public void move(int dx, int dy) { x += dx; y += dy; }
}
class PointList {
Point next, prev;
}
two classes are declared in the compilation unit. The class
Point
 is available out 
side the package
points
, while the class
PointList
 is available for access only
within the package. Thus a compilation unit in another package can access
points.Point
, either by using its fully qualified name:
101






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved