CAN YOU ACCESS NON STATIC VARIABLE IN STATIC CONTEXT ?

Mayank Tripathi

Total Post:807

Points:4035
Posted by  Mayank Tripathi
Java 
 630  View(s)
Ratings:
Rate this:
  1. Mayank Tripathi

    Post:807

    Points:4035
    Can you access non static variable in static context ?

    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.

      Modified On Mar-28-2018 04:50:31 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!