Why is the C equal to 0. What should I do when I want calculate with the modified attributes. Why the C calculate with the default set up variables and not with the modified ones.
public class Object{
int A;
int B;
int C=A+B;
int AddOnetoA(){
A=A+1;
return A;
}
int AddOnetoB(){
B=B+1;
return B;
}
void ShowA() {
System.out.println(A);
}
void ShowB() {
System.out.println(B);
}
void ShowC() {
System.out.println(C);
}
}
And:
public static void main(String[] args) {
Object obj =new Object();
obj.AddOnetoA();
obj.AddOnetoA();
obj.AddOnetoA();
obj.AddOnetoB();
obj.AddOnetoB();
obj.AddOnetoB();
obj.ShowA();
obj.ShowB();
obj.ShowC();
}
output:
3
3
0