wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Can we add two main method in a single class have same signature. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can we add two main method in a single class have same signature." Watch "Can we add two main method in a single class have same signature." New topic
Author

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

gauraw gupta
Greenhorn

Joined: Apr 10, 2011
Posts: 5
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

Joined: Oct 27, 2005
Posts: 19649
    
  18

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?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Madhan Sundararajan Devaki
Ranch Hand

Joined: Mar 18, 2011
Posts: 312

You cannot, as it will result in compilation error. The reason being JVM will not know which method to invoke.


S.D. MADHAN
Not many get the right opportunity !
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

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


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11152
    
  16

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?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
wood burning stoves
 
subject: Can we add two main method in a single class have same signature.
 
Similar Threads
Search problem when using html in DefaultTableCellRenderer
Search problem when using html in DefaultTableCellRenderer
3 top-level elements
Constructor in enum
name of java file