Can we initialize static data members inside non static block ?in Java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can we initialize static data members inside non static block ?in Java

7th Jul 2020, 10:10 PM
Varsha Dustakar
Varsha Dustakar - avatar
2 Answers
+ 7
Yes... a non-static method can access any static variable without creating an instance of the class because the static variable belongs to the class.
8th Jul 2020, 3:47 AM
Aditya
Aditya - avatar
+ 2
Varsha Dustakar please specify language as I see you have opened the python tutorial and machine learning tutorial and have yet to do anything...
7th Jul 2020, 10:24 PM
BroFar
BroFar - avatar