GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java

 Print  |  
Question:  Can we declare multiple main() methods in multiple classes.ie can we have each main method in its class in our program?



December 12, 2005 18:05:49 #4
 Pardeep Saini   Member Since: Visitor    Total Comments: N/A 

RE: can we declare multiple main() methods in multiple...
 
No. We can not declare multiple main() methods as main() method is associated with the static keyword. Whenever the compilation starts compiler looks for the keyword static for compiling the program as static keyword associates with the main() method. This is the reason we need not pass any object to call the main() function. If there will be multiple main() methods then it would be difficult for the compiler to distinguish between the functions i.e to start the compilation from which main() function should be compiled first.
     

 

Back To Question