java - Static method used in a class -


i have static method(additem) in class, why need wrap additem(..) uses static parenthesis? why need static word? tnx

public class something{   static {          additem(new dummyitem("1", "a"));         additem(new dummyitem("2", "b"));         additem(new dummyitem("3", "c"));     }      private static void additem(dummyitem item) {        ......     }   } 

the static block

static {     .... } 

defines static initializer. block of code run once, when class initialized. can call static methods in method, not in static intializers. example write

public void foo() {     something.additem(new dummyitem("1", "a")); } 

this code called whenever method foo() called.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -