public class Solution {
public static int A = 5;
public int B = 2;
public static int C = A * B;
public static void main(String[] args) {
A = 15;
}
}
As i m confused How a non-static variable C can access static variable A in it. this is a task from level 6 lesson 11 task 3. please help me out I m confused
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
25 November 2019, 15:22
What is the task asking you to do. This code will fail because a static variables are initialized first, and because of this the variable B does not exist for variable C when it tries to set its initial value to A * B. For this code to work C would have to be non static, or B would have to be static.
0