???
public class Solution {
public static int A = 5;
public static int B = 2;
public int C = A * B;
public int D = B * A;
public static void main(String[] args) {
}
public int getValue() {
return D;
}
public static int getValue2() {
return C;
}
}
whats the problem here
Under discussion
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
ddi
9 July 2019, 11:19
The int a and b are static and cant be called by a non static int.
public static int A = 5;
public static int B = 2;
public int D = B * A;
The three of them need to be static.
+2
Johannes
12 March 2020, 17:23
so why is it not consistent ? Why can non-static C call A and B ?
0
Peter Gray
14 May 2020, 18:49
It would be fine to make C and D non static if not for the methods in the main class.
The one that calls C is non static.
The one that calls D is static so int D must be static either.
And it's fine for the non-static C to call to static variables A and B.
0
ThomasLC
31 May 2019, 05:29
Move to static modifier from getValue2 to the int D declaration
+2