6.3.1
Hiding Names
NAMES
If the standard naming conventions ( 6.8) are followed, then hiding that
would make the identification of separate naming contexts matter should be rare.
The following contrived example involves hiding because it does not follow the
standard naming conventions:
class Point { int x, y; }
class Test {
static Point Point(int x, int y) {
Point p = new Point();
p.x = x; p.y = y;
return p;
}
public static void main(String[] args) {
int Point;
Point[] pa = new Point[2];
for (Point = 0; Point < 2; Point++) {
pa[Point] = new Point();
pa[Point].x = Point;
pa[Point].y = Point;
}
System.out.println(pa[0].x + "," + pa[0].y);
System.out.println(pa[1].x + "," + pa[1].y);
Point p = Point(3, 4);
System.out.println(p.x + "," + p.y);
}
}
This compiles without error and executes to produce the output:
0,0
1,1
3,4
Within the body of
main
, the lookups of
Point
 find different declarations depend 
ing on the context of the use:
In the expression  
new Point[2]
 , the two occurrences of the class instance
creation expression  
new Point()
 , and at the start of three different local
variable declaration statements, the
Point
 is a
TypeName
 ( 6.5.4) and
denotes the class type
Point
 in each case.
In the method invocation expression  
Point(3, 4)
  the occurrence of
Point
is a
MethodName
( 6.5.6) and denotes the class (
static
) method
Point
.
All other names are
ExpressionName
s ( 6.5.5) and refer to the local variable
Point
.
84






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