static fields: testcase: overwriting of fields
authorBernhard Urban <lewurm@gmail.com>
Mon, 23 Apr 2012 23:22:24 +0000 (01:22 +0200)
committerBernhard Urban <lewurm@gmail.com>
Tue, 24 Apr 2012 09:11:35 +0000 (11:11 +0200)
Makefile
tests/Static4.java [new file with mode: 0644]

index 9e1a9b4eeff6db789c3ef842c2dc379a22488518..38fee4449cdec32e21b4fc6d70b6dc6e3875b0a0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -33,6 +33,8 @@ test: mate $(CLASS_FILES)
        @printf "should be:  0x%08x\n" 0x55
        ./$< tests/Static3 | grep mainresult
        @printf "should be:  0x%08x\n" 0x6dd
+       ./$< tests/Static4 | grep mainresult
+       @printf "should be:  0x%08x 0x%08x\n" 0x33 0x77
        ./$< tests/CallConv1 | grep mainresult
        @printf "should be:  0x%08x\n" 0x1337
        ./$< tests/CallConv2 | grep mainresult
diff --git a/tests/Static4.java b/tests/Static4.java
new file mode 100644 (file)
index 0000000..7f17bf9
--- /dev/null
@@ -0,0 +1,24 @@
+package tests;
+
+public class Static4 extends Static1 {
+       public static int x;
+       public static int y;
+
+       public static void main(String []args) {
+               Static1.setNumbers();
+               Static4.setNumbers();
+               Static1.addNumbers(); // 0x33
+               // System.out.printf("%x\n", Static1.addNumbers());
+               Static4.addNumbers(); // 0x77
+               // System.out.printf("%x\n", Static4.addNumbers());
+       }
+
+       public static void setNumbers() {
+               Static4.x = 0x44;
+               Static4.y = 0x33;
+       }
+
+       public static int addNumbers() {
+               return Static4.x + Static4.y;
+       }
+}