• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to run a program with multiple classes in command prompt.

Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have compiled and successfully ran 5 programs as of now. The common thing in all the programs were that the entire program was inside a single class. But now as I have moved to the further chapters I am finding programs with more than 1 class. What do I do in this case? Should I write all the programs in a single .java file or should I save them as different .java files? How do I actually compile these in Command Prompt?

Can anyone explain this to me?
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can either put each class in in a separate file or, though this is not considered good programming practice, you can put them all in one file.

When you compile the class containing the main method all other classes the main class needs will also automatically be compiled.
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You compile them the same way you compile now--you already know how to specify classpaths. You run them the same way.
Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic