answersLogoWhite

0


Best Answer

Making main static is probably not a good idea; it may keep the linker from recognizing the program entry point. main is not a method, so it cannot be anything but public, for all intents and purposes. Declaring main to have a void return and/or with a void argument list is usually harmless, although it limits how your program can interact with the OS.

User Avatar

Wiki User

βˆ™ 17y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: If we interchange public static and void main then what happens?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

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[])


What if you write static public void instead of public static void?

It would actually make no difference. The presence of the keywords during the declaration of the main method is important and not the order. so a static public void main(String[] args) would just compile and run perfectly fine just like public static void main(String[] args)


What is psvm in java?

public static void main


Does the order of public and static declaration matter in main method?

No


What if static public instead of public static in main?

Try it! If both can be compiled, the result will be the same; if any of them won't compile, settle for the other.


Can you have two mains in java?

Yes... We can have more than one main in JAVA... Just make the only one main method as public and other as default access specifier.... public class Test { public static void main(String args[]) { } } class Test1 { public static void main(String args[]) { } } class Test2 { public static void main(String args[]) { } } Just copy the above code and try.... Have fun in learning... :-) :) :-)


Is there any change by interchanging the position of main in Public static void main in java?

No. You can write it in as many ways as you want. The words public, static and void can be interchanged during the method declaration and still the main() method will continue to work in the same way. i.e., public static void main(String[] args) is the same as static public void main(String[] args) However, if you miss either of these 3 keywords from the method signature, the compiler will still let you compile the method, but it just won't be the main method that can be used to start the program execution.


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();


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'.


How many types can write public static void main in java?

You can write it in as many ways as you want. The words public, static and void can be interchanged during the method declaration and still the main() method will continue to work in the same way. i.e., public static void main(String[] args) is the same as static public void main(String[] args) However, if you miss either of these 3 keywords from the method signature, the compiler will still let you compile the method, but it just won't be the main method that can be used to start the program execution.


Public static void main?

"Public" means that anyone can call the method "static" means that that it will not change "void" means that it will not return any value "main" is the actual name that the compiler looks for to run the program I hope this helps.