Thursday, 23 May 2013

Java Main Method Interview Questions


1. Should a main() method be compulsorily declared in all java classes?
No not required. main() method should be defined only if the source class is a java application. 

2. What is the return type of the main() method?
Main() method doesn't return anything hence declared void. 

3. Why is the main() method declared static?
main() method is called by the JVM even before the instantiation of the class hence it is declared as static. 

4. What is the arguement of main() method? 
main() method accepts an array of String object as arguement.

5. Can a main() method be overloaded?
Yes. You can have any number of main() methods with different method signature and implementation in the class.

6. Can a main() method be declared final? 
Yes. Any inheriting class will not be able to have it's own default main() method. 

7. Does the order of public and static declaration matter in main() method?
No. It doesn't matter but void should always come before main(). 

More Questions on Main Method

1 comments so far

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.


EmoticonEmoticon