EXPRESSIONS
Compile Time Step 2: Determine Method Signature
15.11.2
Here the most specific declaration of method
test
 is the one taking a parameter
of type
ColoredPoint
. Because the result type of the method is
int
, a compile 
time error occurs because an
int
 cannot be converted to a
String
 by assignment
conversion. This example shows that, in Java, the result types of methods do not
participate in resolving overloaded methods, so that the second
test
 method,
which returns a
String
, is not chosen, even though it has a result type that would
allow the example program to compile without error.
15.11.2.5
Example: Compile Time Resolution
The most applicable method is chosen at compile time; its descriptor determines
what method is actually executed at run time. If a new method is added to a class,
then Java code that was compiled with the old definition of the class might not use
the new method, even if a recompilation would cause this method to be chosen.
So, for example, consider two compilation units, one for class
Point
:
package points;
public class Point {
public int x, y;
public Point(int x, int y) { this.x = x; this.y = y; }
public String toString() { return toString(""); }
public String toString(String s) {
return "(" + x + "," + y + s + ")";
}
}
and one for class
ColoredPoint
:
package points;
public class ColoredPoint extends Point {
public static final int
RED = 0, GREEN = 1, BLUE = 2;
public static String[] COLORS =
{ "red", "green", "blue" };
public byte color;
public ColoredPoint(int x, int y, int color) {
super(x, y); this.color = (byte)color;
}
329






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