+ 1

Can anyone explain what is static keyword in public static void main actually mean?

3rd Aug 2018, 10:01 AM
Kundan Saridevi
Kundan Saridevi - avatar
5 Réponses
+ 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.
3rd Aug 2018, 10:11 AM
Jeroen van der Laan
Jeroen van der Laan - avatar
+ 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.
3rd Aug 2018, 11:36 AM
Maninder $ingh
Maninder $ingh - avatar
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
3rd Aug 2018, 1:40 PM
Supriya Gangapatnam
Supriya Gangapatnam - avatar
0
Thanks everyone
20th Aug 2018, 10:46 AM
Kundan Saridevi
Kundan Saridevi - avatar