what is the difference between static method and static block? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what is the difference between static method and static block?

8th Aug 2016, 5:50 PM
srilekha
4 Answers
0
Static Methods static methods can access class variables without using object of class Static Block static block is used for changing the default values of static variables.A class can have multiple static blocks
8th Aug 2016, 6:39 PM
Suhail Pappu
Suhail Pappu - avatar
0
static blocks are automatically executed when program control goes to class and for static method we have to call by using class name
8th Aug 2016, 7:29 PM
prasad
prasad - avatar
0
Static method - A static method belongs to the class rather than object of a class. - A static method can be invoked without the need for creating an instance of a class. - Static method can access static data member and can change the value of it. Static block - Is used to initialize the static data member. - It is executed before main method at the time of classloading.
13th Aug 2016, 3:12 PM
WPimpong
WPimpong - avatar
0
thanks
13th Aug 2016, 3:16 PM
srilekha