File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we add two main method in a single class have same signature.

 
gauraw gupta
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can it possible to add two main method public static void main(String args[]) in a single class.
Also please provide me the some information that a Class and Object are a simple class or abstract class or interface.

Thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20396
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gauraw gupta wrote:Can it possible to add two main method public static void main(String args[]) in a single class.

Have you already tried? If yes, what were the results? And why would you get those results?
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot, as it will result in compilation error. The reason being JVM will not know which method to invoke.
 
Maneesh Godbole
Saloon Keeper
Posts: 10976
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also please provide me the some information that a Class and Object are a simple class or abstract class or interface.

Recommended reading: http://www.coderanch.com/how-to/java/InterfaceVsAbstractClass
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12022
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you ever have two methods with the exact same signature, regardless of the name, in a single class? Why would 'main' be any different?

if you did have it in there twice, how would the JVM decide which one to use when it starts?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic