paul@67 | 1 | public class StaticTest { |
paul@67 | 2 | |
paul@67 | 3 | public static StaticTestClass staticMember = StaticTestClass.newInstance(); |
paul@67 | 4 | public static StaticTestClass staticMember2 = StaticTestClass.newInstance(123); |
paul@67 | 5 | public static int staticMember3 = StaticTestClass.getNumber(); |
paul@146 | 6 | |
paul@146 | 7 | public static void main(String[] args) { |
paul@146 | 8 | if (StaticTest.staticMember != null && StaticTest.staticMember.x == 321) { |
paul@146 | 9 | System.out.println("StaticTest.staticMember.x correct: " + StaticTest.staticMember.x); |
paul@146 | 10 | } else { |
paul@146 | 11 | System.out.println("StaticTest.staticMember.x failed!"); |
paul@146 | 12 | } |
paul@146 | 13 | if (StaticTest.staticMember2 != null && StaticTest.staticMember2.x == 123) { |
paul@146 | 14 | System.out.println("StaticTest.staticMember2.x correct: " + StaticTest.staticMember2.x); |
paul@146 | 15 | } else { |
paul@146 | 16 | System.out.println("StaticTest.staticMember2.x failed!"); |
paul@146 | 17 | } |
paul@146 | 18 | if (StaticTest.staticMember3 == 456) { |
paul@146 | 19 | System.out.println("StaticTest.staticMember3 correct: " + StaticTest.staticMember3); |
paul@146 | 20 | } else { |
paul@146 | 21 | System.out.println("StaticTest.staticMember3 failed!"); |
paul@146 | 22 | } |
paul@146 | 23 | } |
paul@67 | 24 | } |
paul@67 | 25 | |
paul@67 | 26 | class StaticTestClass { |
paul@67 | 27 | public int x; |
paul@67 | 28 | |
paul@67 | 29 | public StaticTestClass() { |
paul@67 | 30 | x = 321; |
paul@67 | 31 | } |
paul@67 | 32 | |
paul@67 | 33 | public StaticTestClass(int x) { |
paul@67 | 34 | this.x = x; |
paul@67 | 35 | } |
paul@67 | 36 | |
paul@67 | 37 | public static StaticTestClass newInstance() { |
paul@67 | 38 | return new StaticTestClass(); |
paul@67 | 39 | } |
paul@67 | 40 | |
paul@67 | 41 | public static StaticTestClass newInstance(int x) { |
paul@67 | 42 | return new StaticTestClass(x); |
paul@67 | 43 | } |
paul@67 | 44 | |
paul@67 | 45 | public static int getNumber() { |
paul@67 | 46 | return 456; |
paul@67 | 47 | } |
paul@67 | 48 | } |
paul@146 | 49 | |
paul@146 | 50 | // vim: tabstop=4 expandtab shiftwidth=4 |