KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > MethodScopedClass


1 /* MethodScopedClass Copyright (C) 1999 Jochen Hoenicke.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; see the file COPYING. If not, write to
15  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  * $Id: MethodScopedClass.java,v 1.1 1999/11/04 00:21:51 jochen Exp $
18  */

19
20 import java.util.Vector JavaDoc;
21
22 public class MethodScopedClass {
23     int var = 3;
24     
25     public void test1() {
26     final long longVar = 5;
27     final int intVar = var;
28     final double dblVar = 3;
29
30     final float fooFloat = 5;
31     final float barFloat = 7;
32     
33     class Hello {
34         int var = (int) longVar;
35
36         {
37         System.err.println("all constructors");
38         }
39         
40         Hello(float f, String JavaDoc info) {
41             System.err.println("construct: "+info+" "+f);
42         }
43
44         Hello(float f) {
45         this(f, "default");
46         }
47
48         public void hello() {
49         System.err.println("HelloWorld: "+dblVar+" "+intVar);
50         }
51     };
52
53     /* This test checks if the variables longVar, intVar and dblVar
54      * can be detected correctly as inner values. The first parameter
55      * of the Hello constructor can't be an outer value, because bar
56      * uses a different value for this.
57      */

58     class foo {
59         foo() {
60         new Hello(fooFloat);
61         }
62     }
63
64     class bar {
65         bar() {
66         new Hello(barFloat, "bar");
67         }
68     }
69
70     new foo();
71     new bar();
72     }
73
74 // public void test2() {
75
// final long longVar = 5;
76
// final int intVar = var;
77
// final double dblVar = 3;
78

79 // final float barFloat = 7;
80

81 // class Hello {
82
// int var = (int) longVar;
83

84 // {
85
// System.err.println("all constructors");
86
// }
87

88 // Hello(int i, String info) {
89
// System.err.println("construct: "+info);
90
// }
91

92 // Hello(int i) {
93
// this(i, "This can only be compiled correctly"
94
// +" by a recent jikes");
95
// }
96

97 // public void hello() {
98
// System.err.println("HelloWorld: "+dblVar+" "+intVar);
99
// }
100
// };
101

102 // /* Similar to the test above. But this time foo is given barFloat
103
// * as parameter.
104
// */
105
// class foo {
106
// foo(int param) {
107
// new Hello(param);
108
// }
109

110 // }
111

112 // class bar {
113
// bar() {
114
// new Hello(barFloat, "bar");
115
// }
116
// test() {
117
// new foo(fooFloat);
118
// }
119
// }
120

121 // new foo(barFloat);
122
// new bar();
123
// }
124
}
125
Popular Tags