Register now or log in to join your professional community.
if we pas the object of the class in the static block the we access the non static variable in the static block
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.