15.11.4
Runtime Evaluation of Method Invocation
EXPRESSIONS
So, for example, in:
class Test {
public static void main(String[] args) {
String s = "one";
if (s.startsWith(s = "two"))
System.out.println("oops");
}
}
the occurrence of
s
before
.startsWith
is evaluated first, before the argument
expression
s="two"
. Therefore, a reference to the string
"one"
is remembered as
the target reference before the local variable s is changed to refer to the string
"two"
. As a result, the
startsWith
method ( 20.12.20) is invoked for target
object
"one"
with argument
"two"
, so the result of the invocation is
false
, as the
string
"one"
does not start with
"two"
. It follows that the test program does not
print
oops
.
15.11.4.9
Example: Overriding
In the example:
class Point {
final int EDGE = 20;
int x, y;
void move(int dx, int dy) {
x += dx; y += dy;
if (Math.abs(x) >= EDGE || Math.abs(y) >= EDGE)
clear();
}
void clear() {
System.out.println("\tPoint clear");
x = 0; y = 0;
}
}
class ColoredPoint extends Point {
int color;
void clear() {
System.out.println("\tColoredPoint clear");
super.clear();
338
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