Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
gauraw gupta
Greenhorn
Posts: 5
  • 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
Posts: 21090
85
Chrome Eclipse IDE Java Windows
  • 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
  • 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
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 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
Posts: 12542
48
Chrome Java Linux
  • 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?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!