Search Interview Questions
| 3268 questions in repository.|
There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Have a video suggestion.
Click Correct / Improve and please let us know.
|Core java - Interview Questions and Answers for 'Ibm pune' - 1 question(s) found - Order By Newest|
|Frequently asked to fresh graduates and less experienced.|
|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 :|
|Like Discuss Correct / Improve  java   main method Asked in 4 Companies basic   frequent|
Try 1 Question(s) Test
| 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
|Can we have multiple main methods in a single class ?|
|Can we overload main method in Java ?|
|What will happen if static modifier is removed from the signature of the main method?|
|How can we execute a Java class independently if it doesn't have a static main method ?|
|Can we declare a main method as abstract ?|
|Do all java classes need a main method?|
|Can we declare the main method as private ?|
|Why main method is declared static ?|