1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
public class Test {
public void maSuperFonction (MonAutreTest t) {
t.setX(1);
t.setY(2);
}
public static void main (String[] args) {
MonAutreTest t2 = new MonAutreTest();
System.out.println("---------------");
System.out.println("x: "+t2.getX()+", y: "+t2.getY()); // affiche x: 0, y: 0
test.maSuperFonction (t2);
System.out.println("x: "+t2.getX()+", y: "+t2.getY()); // affiche x: 1, y: 2
System.out.println("---------------");
}
}
class MonAutreTest {
private int x, y;
public void setX (int x) {
this.x = x;
}
public int getX () {
return x;
}
public void setY (int y) {
this.y = y;
}
public int getY () {
return y;
}
} |