6.6.5
Example: Default Access Fields, Methods, and Constructors
NAMES
package pointsUser;
class Test {
public static void main(String[] args) {
points.Point p = new points.Point();
System.out.println(p.x + " " + p.y);
}
}
or by using a single type import declaration ( 7.5.1) that mentions the fully
qualfied name, so that the simple name may be used thereafter:
package pointsUser;
import points.Point;
class Test {
public static void main(String[] args) {
Point p = new Point();
System.out.println(p.x + " " + p.y);
}
}
However, this compilation unit cannot use or import
points.PointList
, which
is not declared
public
 and is therefore inaccessible outside package
points
.
6.6.5   Example: Default Access Fields, Methods, and Constructors
If none of the access modifiers
public
,
protected
, or
private
 are specified, a
class member or constructor is accessible throughout the package that contains the
declaration of the class in which the class member is declared, but the class mem 
ber or constructor is not accessible in any other package. If a
public
 class has a
method or constructor with default access, then this method or constructor is not
accessible to or inherited by a subclass declared outside this package.
For example, if we have:
package points;
public class Point {
public int x, y;
void move(int dx, int dy) { x += dx; y += dy; }
public void moveAlso(int dx, int dy) { move(dx, dy); }
}
then a subclass in another package may declare an unrelated
move
 method, with
the same signature ( 8.4.2) and return type. Because the original
move
 method is
not accessible from package
morepoints
,
super
 may not be used:
102






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