Teaching - lu2in002 - (TME: sujets)
lu2in002 : Introduction à la programmation Objet
Ce à quoi vous avez échappé en interro: que donne l'exécution du code suivant?
public class Obj {
int x = 1;
int y = 1;
Obj(){
x=0; y=0;
}
Obj(int x){
x++;
y=x;
}
Obj(int x, int y){
this(x);
System.out.println(x+" "+y);
this.x = x+y;
}
public static void main(String[]args){
Obj a = new Obj();
Obj b = new Obj(a.y);
Obj c = new Obj(b.x, a.y);
a=b;
System.out.println(a.y);
System.out.println(a.x+" "+b.y+" "+c.x+" "+c.y);
}
}
int x = 1;
int y = 1;
Obj(){
x=0; y=0;
}
Obj(int x){
x++;
y=x;
}
Obj(int x, int y){
this(x);
System.out.println(x+" "+y);
this.x = x+y;
}
public static void main(String[]args){
Obj a = new Obj();
Obj b = new Obj(a.y);
Obj c = new Obj(b.x, a.y);
a=b;
System.out.println(a.y);
System.out.println(a.x+" "+b.y+" "+c.x+" "+c.y);
}
}