Search Interview Questions | 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. |
|
| |||||||||||
Core Java - Interview Questions and Answers for 'Main method' - 15 question(s) found - Order By Rating | |||||||||||
| |||||||||||
Ans. public static void main(String[] args) | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  main method | |||||||||||
| |||||||||||
Ans. Array of strings in the main method are the list of arguments or parameters which are sent to the application / program. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  main method   main method string array argument | |||||||||||
| |||||||||||
Ans. No without main method can not be executed it will throw an error illegal start of type. Main method is the entry point of application. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  jvm  compilation  main method Basic | |||||||||||
| |||||||||||
Ans. No. It won't be null but an empty array with size 0 | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  main method | |||||||||||
| |||||||||||
Ans. We can overload the main method by specifying different argument types. For example - 2 main methods with different arguments is perfectly legal public static void main(); public static void main(String[] args); The following are not legal as compiler will complain of duplicate methods public static void main(String[] args); public static void main(String[] args); Even The following are not legal as we cannot overload on return types public static String main(String[] args); public static void main(String[] args); | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  main method Asked in 2 Companies | |||||||||||
| |||||||||||
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 : | |||||||||||
Like Discuss Correct / Improve  main method Asked in 3 Companies | |||||||||||
| |||||||||||
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 : | |||||||||||
Like Discuss Correct / Improve  main method  static Asked in 4 Companies Basic | |||||||||||
| |||||||||||
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 : | |||||||||||
Like Discuss Correct / Improve  main method   main method visibility basic | |||||||||||
Try 1 Question(s) Test | |||||||||||
| |||||||||||
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 : | |||||||||||
Like Discuss Correct / Improve  main method | |||||||||||
| |||||||||||
Ans. No. Static methods cannot be overridden and hence make no sense to be declared abstract. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  main method   abstract | |||||||||||
Try 1 Question(s) Test | |||||||||||
| |||||||||||
Ans. Program throws "NoSuchMethodError" error at runtime . | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java   main method   main   static   static method   nosuchmethoderror | |||||||||||
| |||||||||||
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 : | |||||||||||
Like Discuss Correct / Improve  java   main method   overloading   yes-no Asked in 6 Companies intermediate   frequent | |||||||||||
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 | |||||||||||
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 : | |||||||||||
Like Discuss Correct / Improve  main method   java | |||||||||||
| |||||||||||
Ans. We can override main method | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java   main method | |||||||||||
| |||||||||||
| |||||||||||