- Code: Alles auswählen
public class A {
protected int x = 1;
public A() {
this(4);
}
public A(int x) {
this.x += x;
}
protected void f(B b) {
this.x += b.x;
}
}
public class B extends A {
protected static int y = 3;
public B() {
}
public B(int x) {
super(x);
y--;
}
protected void f(B b) {
x += b.y;
}
protected void f(A a) {
a = this;
}
}
public class M {
public static void main(String[] args) {
A a = new A();
System.out.println(a.x); // OUT: 5
B b = new B(10);
System.out.println(b.x+" "+b.y); // OUT: 11 2
a.f(b);
System.out.println(a.x); // OUT: 16
b.f(b);
System.out.println(b.x+" "+b.y); // OUT: 13 2
b.f(a);
System.out.println(a.x); // OUT: 16
b.f(new B());
System.out.println(b.x); // OUT: 15
}
}
Kann mir jemand die letzten beiden Ausgaben genau erklären?[/code]