Monday, April 07, 2025

LATEST UPDATES
>> What is the difference between continue and break statement?  >> What is a singleton class? Give a practical example of its usage.  >> What’s the purpose of Static methods and static variables?  >> What are the various access specifiers for Java classes?  >> What is the difference between an Inner Class and a Sub-Class?    

Friday, 18 November 2016

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.

No comments:

Post a Comment

Designed By Seo Blogger Templates