answersLogoWhite

0

Why main is static?

Updated: 8/16/2019
User Avatar

Wiki User

14y ago

Best Answer

The main method is static because the JVM would be invoking this method as the starting point of execution. If this is like other normal methods, the JVM would have to instantiate an object of the class before it can call it. This is not possible because this is the starting point. If the main method is static the JVM can directly call this by specifying the class name.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why main is static?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Is the pressure in a water main static?

No, it is not static


Is it compulsory to write static with void main?

Every C# application is started on the startup class' static Main method. Yes, it must be static, but void is not the only returned type. The 4 signatures:static void Main();static void Main(string[] arguments);static int Main();static int Main(string[] arguments);Ideally, there should be one and only one Main method in your application.


Why you use main method when you can use static method?

The main method is called by the jvm when your program is executed. The main method is a static method: public static void main(String[] args) {} A static method is method that can be run without instantiate the class (creating an object from it) The main method is a static method. No other static method could replace it's functionality. PS By static method do you mean static initialiser? I often use static initialisers instead of a main method, but in these cases you must still have a main method, albeit an empty one ie. public static void main(String[] args) {} Notice that the method has an empty body A main method must be used if you intend to accept parameters at run time from the jvm.


Can you overwrite main function in java?

You can not overwrite a static method in Java,and 'main' is a static method.so,you can't overwrite the 'main'.


Is it possible to create a static object in main?

Yes, anywhere that you can normally declare an object you can use the static keyword to make that object static.int main (){static Object o;}


What are the valid signatures of the main method of a class?

The main method can be declared as either of the below: public static void main(String[] args) or public static void main(String args[])


Which method is called first of all other methods when any application executed in c sharp?

static method Main() of the start object/class.There are 4 different signatures of Main():static void Main();static int Man();static void Main(string[] args);static int Main(string[] args);The starting object/class can have only one of them. Other classes or objects may have Main() method as well. (But why would be the question, Main() is NOT a good OO method name anyway. Method name should be a verb or start with a verb)


What is the format of java file?

Class Ram { static {} //static block to execute something before main method Ram() //constructor {} {} //init block public static void main(String ss[]) { } other methods }


Why the main function is public and static?

The main function is public because it means it needs to be called by any object. I had to check this myself but if you try to make the main function in Java private it will give you a run time error. It is static because it is indicating it is a class method and it does not need to be instantiated. Without the static keyword you would need to do something like this Main main = new Main();


Who is the static character romeo and Juliet?

main charcters


What is the main purpose of bonding drums or containers?

Static


What is psvm in java?

public static void main