java 代码
- //静态方法是从上向下执行的;
- class TestStatic
- {
- public static TestStatic ts = new TestStatic();
- public static int x = 0;
- public static int y;
- private TestStatic()
- {
- x++;
- y++;
- }
- public static TestStatic run()
- {
- return ts;
- }
- public static void main(String[] args)
- {
- TestStatic ts = TestStatic.run();
- System.out.println(ts.x);
- System.out.println(ts.y);
- }
- }
- 其结果为:0,1;
另外:
java 代码
- class TestStatic
- {
- public static int x = 0;
- public static int y;
- public static TestStatic ts = new TestStatic();
- private TestStatic()
- {
- x++;
- y++;
- }
- public static TestStatic run()
- {
- return ts;
- }
- public static void main(String[] args)
- {
- TestStatic ts = TestStatic.run();
- System.out.println(ts.x);
- System.out.println(ts.y);
- }
- }
- //其结果为:1,1;