Can you access non static variable in static context ?5
853 5b5cc7cee4d2b4197775110a
Q: Can you access non static variable in static context ?
- Show Answer
- Workspace
- Discuss
Answer :
Explanation :
A static variable in Java belongs to its class and its value remains the same for all its instances. A static variable is initialized when the class is loaded by the JVM. If your code tries to access a non-static variable, without any instance, the compiler will complain, because those variables are not created yet and they are not associated with any instance.
Similar Questions
Since Nithya and Suganya exchange places, so Rita’s new position is the same as Monika’s earlier position. This position is 17th from the right and 10th from the left. Therefore Number of girls in the row = (16 + 1 + 9) = 26.