public class Line
1: //Line.java
2: //Illustrates an "inner class".
3: //Note the files produced upon compilation.
5: public class Line
6: {
7: private class Point
8: {
9: int x;
10: int y;
12: Point() { x=0; y=0; }
13: Point(int x, int y)
14: {
15: this.x = x;
16: this.y = y;
17: }
18: }
20: private Point start;
21: private Point end;
24: public double length()
25: {
26: return Math.sqrt((end.x-start.x) * (end.x-start.x) +
27: (end.y-start.y) * (end.y-start.y));
28: }
30: public Line()
31: {
32: start = new Point();
33: end = new Point();
34: }
36: public Line(int p1x, int p1y, int p2x, int p2y)
37: {
38: start = new Point(p1x, p1y);
39: end = new Point(p2x, p2y);
40: }
42: }