NAMES
Example:
public
Fields, Methods, and Constructors
6.6.6
package morepoints;
public class PlusPoint extends points.Point {
public void move(int dx, int dy) {
super.move(dx, dy);
//
compile time error
moveAlso(dx, dy);
}
}
Because move of
Point
is not overridden by
move
in
PlusPoint
, the method
moveAlso
in
Point
never calls the method move in
PlusPoint
.
Thus if you delete the
super.move
call from
PlusPoint
and execute the test
program:
import points.Point;
import morepoints.PlusPoint;
class Test {
public static void main(String[] args) {
PlusPoint pp = new PlusPoint();
pp.move(1, 1);
}
}
it terminates normally. If move of
Point
were overridden by
move
in
PlusPoint
,
then this program would recurse infinitely, until a
StackoverflowError
occurred.
6.6.6 Example:
public
Fields, Methods, and Constructors
A
public
class member or constructor is accessible throughout the package
where it is declared and from any other package that has access to the package in
which it is declared ( 7.4.4). For example, in the compilation unit:
package points;
public class Point {
int x, y;
public void move(int dx, int dy) {
x += dx; y += dy;
moves++;
}
public static int moves = 0;
}
103
footer
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