More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Ans. 1. public is the access modifier that makes the method accessible from anywhere, static is the keyword that makes it accessible even without creating any object, void means it doesn't return anything , String args[] is the array of argument that the method receives.
2. If we use main without the string args , it will compile correctly as Java will treat it as just another method. It wont be the method "main" which Java looks for when it looks to execute the class and hence will throw
Error: Main method not found in class , please define the main method as:
public static void main(String[] args)
3. Main is not a keyword but a special string that Java looks for while initiating the main thread.
Help us improve. Please let us know the company, where you were asked this question :
Which of the following is false about main method ?
It should be declared public and static
it should have only 1 argument of type String array
We can override main method
We can overload main method
Q2. Which of the following is false about main method ?
a. It should be declared public and static
b. it should have only 1 argument of type String array
c. We can override main method
d. We can overload main method
Ans. Yes, but the overloaded main methods without single String[] argument doesn't get any special status by the JVM. They are just another methods that needs to be called explicitly.
Help us improve. Please let us know the company, where you were asked this question :
Q5. What will happen if static modifier is removed from the signature of the main method?
Ans. Program throws "NoSuchMethodError" error at runtime .
Help us improve. Please let us know the company, where you were asked this question :
LikeDiscussCorrect / Improve  java   main method   main   static   static method   nosuchmethoderror
Q6. How can we execute a Java class independently if it doesn't have a static main method ?
a. By initiating the flow in any of the static method b. By initiating the flow in any of static block c. By initiating the flow in any other instance method named as main d. By initiating the flow in any other instance method named as main and making it final
Ans. By initiating the flow in any of static block
Help us improve. Please let us know the company, where you were asked this question :
Which of the following is false about main method ?
It should be declared public and static
it should have only 1 argument of type String array
We can override main method
We can overload main method
Q8. Do all java classes need a main method?
Ans. No, Main method is the entry point into an application. An application usually contain multiple classes to perform a function.
Lets take an example of a House, House usually have only one external Door and you may have internal doors to move around within a house. Internal Doors are methods of classes whereas External Door is a special method called main method.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Yes, compiler won't complain but at runtime it will give an error saying "Error: Main method not found in class". Even though we can use this method as any other private method, it cannot be invocate by executing the class.
Help us improve. Please let us know the company, where you were asked this question :
Ans. static is the keyword that makes it accessible even without creating any object and using class name only. Making it non static would like creation of object upfront before calling the method.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Yes we can have a main method with string[] argument in every class of an application. When we execute an app we specify the starting point i.e the class that will get the control first and hence main method of that class gets executed.
Help us improve. Please let us know the company, where you were asked this question :
Q12. If we don't provide any argument to the executed program, What arguments will be passed to the main method ? Will the String array argument be null ?