本帖最后由 官珺伟 于 2014-1-3 15:17 编辑
- class Count
- {
- public static int counter;
- static
- {
- counter=123;
- System.out.println("Now in static block.");
- }
- public void test
- {
- System.out.println("test method=="+counter);
- }
- }
- public class Test
- {
- public static void main(String args[])
- {
- System.out.println("counter="+Count.counter);
- new Count().test();
- }
- }
- //运行结果是:
- //Now in static block.counter=123
- //test method==123
复制代码
|