+ 1

Why we use static in java

"public static void main" so in this why we use static

12th Jul 2017, 7:18 AM
Harley Brahmbhatt
Harley Brahmbhatt - avatar
2 Réponses
+ 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
12th Jul 2017, 8:04 AM
Ant●ny
+ 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.
14th Jul 2017, 5:05 PM
Rachid Snowrise
Rachid Snowrise - avatar