• Post Reply Bookmark Topic Watch Topic
  • New Topic

Three main methods  RSS feed

 
Rrohit rakesh upadhyay
Ranch Hand
Posts: 94
1
Java Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote the following code and noticed that only class B's main method was executing,Should not all the main methods be executing?And why only class B's why not class A's or C's?
And when i removed main methods from class A and B i got a runtime error "Main methon not foun in class B...............................................".Can anyone explain why?

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37496
540
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good question. When you run the program, what command do you use? java B?

If so, that is what tells Java what class to look in for the main method. Only one main method can be kicked off by the java command.

If you put these three classes in separate files, it would be clearer as to which method is run.
 
Rrohit rakesh upadhyay
Ranch Hand
Posts: 94
1
Java Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Clear as day now.Thank you Jeanne
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why did you expect the A method to run? Remember static methods do not override each other. Look at this FAQ.
Why did you write the import declaration? You don't appear to be using anything from the java.io package.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!