Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Saumya Purkayastha
Greenhorn
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?
 
Christiaan Lombard
Greenhorn
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.
 
David Newton
Author
Rancher
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic