ja .. du kan ikke skrive statements, hvor du gør i main-class'en
prøv class main { public static void main(String[] args) { A x = new A(); A y = new A(); x.foo(11); y.foo(12); System.out.println("x.x = "+ x.x + "y.y = "+ y.y);} } }
class main { public static void main(String args[]) { A x = new A(); A y = new A(); x.foo(11); y.foo(12); System.out.println("x.x = "+ x.x + "y.y = "+ y.y); } }
derudover bør du tilgå x-variablen i A med en get metode
altså class A { int x public A() { x = 7; } void setX(int newX) { this.x = newX; } int getX() { return this.x; } }
class Main { public static void main(String[] args) { A x = new A(); A y = new A(); x.setX(11); y.setX(12); System.out.println("x.x = "+ x.getX() + "y.y = "+ y.getX() ); } }
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.