+ 1
Why we use static in java
"public static void main" so in this why we use static
2 Respostas
+ 16
When the JVM makes call to the main method there is no object existing for the class being called. therefore it has to have static method to allow invocation from class.
in other words :
because of static we no need to create object for main method class.
public -its the access specifier means from every where we can access it; static -access modifier means we can call this method directly using class name without creating an object of it; void - its the return type; main - method name string [] args - it accept only string type of argument..and stores it in a string
+ 2
'static' means the variable or method is defined for the class itself; this is in contrast to an instance variable, which is defined for objects that are instances of the class.
Therefore, if you have a static variable, then no matter how many objects you have that are instances of that class, you still only have one variable by that name. You have a different set of instance variables for each object, but only one of each static variable.