| 1 | {{{ |
| 2 | // 存為 Test.java |
| 3 | import java.io.*; |
| 4 | import java.lang.String; |
| 5 | |
| 6 | public class Test |
| 7 | { |
| 8 | public String myData; |
| 9 | |
| 10 | public String getMyData() |
| 11 | { |
| 12 | return myData; |
| 13 | } |
| 14 | |
| 15 | public void setMyData(String data) |
| 16 | { |
| 17 | myData = new String(data); |
| 18 | } |
| 19 | |
| 20 | public static void main(String args[]) { |
| 21 | System.out.print("args.length=" + args.length); |
| 22 | System.out.print("\n"); |
| 23 | if(args.length < 2) |
| 24 | { |
| 25 | System.out.print("Usgage: java Test myData myWeight"); |
| 26 | System.exit(1); |
| 27 | } |
| 28 | Test myTest = new Test(); |
| 29 | myClass myclass = new myClass(); |
| 30 | myTest.setMyData(args[0]); |
| 31 | System.out.print(myTest.getMyData()); |
| 32 | System.out.print("\n"); |
| 33 | System.out.print(myclass.getWeight()); |
| 34 | System.out.print("\n"); |
| 35 | myclass.setWeight(args[1]); |
| 36 | System.out.print(myclass.getWeight()); |
| 37 | } |
| 38 | } |
| 39 | }}} |
| 40 | {{{ |
| 41 | public class myClass |
| 42 | { |
| 43 | public String myWeight; |
| 44 | |
| 45 | public String getWeight() |
| 46 | { |
| 47 | return myWeight; |
| 48 | } |
| 49 | |
| 50 | public void setWeight(String weight) |
| 51 | { |
| 52 | myWeight = new String(weight); |
| 53 | } |
| 54 | |
| 55 | public myClass() |
| 56 | { |
| 57 | setWeight("50"); |
| 58 | } |
| 59 | |
| 60 | public static void main(String args[]) { |
| 61 | myClass myclass = new myClass(); |
| 62 | System.out.print(myclass.getWeight()); |
| 63 | } |
| 64 | } |
| 65 | }}} |
| 66 | }}} |