Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Is it possible to access non static variable inside the static block, and how?

user-image
Question added by pushpa latha ANNELA , data verification , success solutions
Date Posted: 2016/06/14

if we pas the object of  the class in the static block the we access the non static variable  in the static block

Mostafa ElSheikh
by Mostafa ElSheikh , Software Development Engineer II (L5) , Amazon

Actually, It's not possible to access a non-static variable inside a static block.

Static variable is a class variable; you can access it through the name of class without creating an object from that class.

Example: MyClass.myVariable = 5;

Moreover, you can access it through the reference of the object of that class

Example: myRef.myVariable = 5;

They're strictly the same.

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.