+ 1
Can anyone explain what is static keyword in public static void main actually mean?
5 Respostas
+ 3
Static is a keyword to define a method that is accessible via the class, whereas without this keyword, a method is accessible via the objects that a class creates.
If main would not be static, an object of the class where main is defined would first have to be created in order to call it.
With main being static, it can be called directly by referencing the class.
+ 3
static is a non-access modifier in Java which is applicable for the following:
blocks
variables
methods
nested classes
To create a static member(block,variable,method,nested class), precede its declaration with the keyword static. When a member is declared static, it can be accessed before any objects of its class are created, and without reference to any object.
Static blocks
If you need to do computation in order to initialize your static variables, you can declare a static block that gets executed exactly once, when the class is first loaded.
0
we call the methods using methodcall(. operator) but who calls main method...
why first main method runs..because jvm calls the main method .
This can be done by static keyword .
static is a class variable doesn't belong to class/instance of class
0
Thanks everyone