本帖最後由 hellokerby 於 2013-9-19 16:56 編輯
段code 係示範Array 既例子- class Account {
- int a;
- int b;
- public void setData(int c, int d) {
- a = c;
- b = d;
- }
- public void showData() {
- System.out.println("Value of a =" + a);
- System.out.println("Value of b =" + b);
- }
- }
- class ObjectArray {
- public static void main(String args[]) {
- Account obj[] = new Account[2];
- obj[0] = new Account();
- obj[1] = new Account();
- obj[0].setData(1, 2);
- obj[1].setData(3, 4);
- System.out.println("For Array Element 0");
- obj[0].showData();
- System.out.println("For Array Element 1");
- obj[1].showData();
- }
- }
複製代碼 唔明點解要int c, d, 乜無得直接用番a,b 咩 ?- public void setData(int c, int d) {
- a = c;
- b = d;
- }
複製代碼 |