Hallo,
ich habe hier ein kleines Problem. Ich verstehe nicht warum die variable "m" für alle existierenden Instanzen hochgezählt wird.
Speziell geht es um den Punkt den ich kommentiert habe.
Danke für die Hilfe
ich habe hier ein kleines Problem. Ich verstehe nicht warum die variable "m" für alle existierenden Instanzen hochgezählt wird.
Speziell geht es um den Punkt den ich kommentiert habe.
Java:
public class M {
int m = 3;
public M succ() {
m++;
return this;
}
public int triplyAdd(int z) {
return 3 * m + z;
}
public void fill(int[] a) {
for (int i = 0; i < a.length; i++)
a[i] = m - i;
}
public void fill(int z) {
z = m;
}
public static void main(String[] args){
int y, z = 2;
M b;
M a = new M(); /*i*/
System.out.println(a.m);
b = a.succ(); /*ii*/
System.out.println(b.m);
System.out.println(a.m); // Warum ist a.m hier auch 4?
y = a.triplyAdd(z); /*iii*/
y = a.m; /*iv*/
y = a.succ().succ().triplyAdd(3); /*v*/
a.fill(a.m); /*vi*/
a.m = 10;
int[] f = {y,y,y};
b.fill(f); /*vii*/
System.out.println(f[1]); /*viii*/
System.out.println(f[2]); /*ix*/
}
}
Danke für die Hilfe