• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Compile main at different class

 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'd apprecitate if anyone can explain the following compilation rules.
I'm trying to create 2 classes in the same file with a main method in either class.
The class file will only run if the main is in the class or the superclass of the filename.
Is this observation correct? And why is it done this way?
Thanks for any advice.
Cheers.

Han Ming
//filename D.java - run OK

//filename D.java - run OK

//filename B.java - run OK

//filename B.java - run Error :- NoSuchMethodError
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The class file will only run if the main is in the class or the superclass of the filename.
Is this observation correct?


Yes - your observation is correct

And why is it done this way?


!!??? - You need to ask James Goslig.
You need to start somewhere. The class you give to java must contain a main() method - either in or inherited. - This was the case in your first 3 cases. This is just like in OLD "C" programs, where the execution starts in the main(argv, argc) method.
This was NOT the case in your 4th example. Hence "NoSuchMethod" Error
 
HanMing Low
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for the explanation.
I think your explanation is easier to remember.


!!??? - You need to ask James Goslig.



Thanks again.
Cheers.

Han Ming
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic