Home > DeveloperSection > Interviews > Can you access non static variable in static context ?

Posted on    July-27-2015 3:35 AM

 Java Java 
 1 Answer(s)
  374  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Posted on    July-27-2015 3:35 AM

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.

Don't want to miss updates? Please click the below button!

Follow MindStick