Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects (Retired) Harnessing the Power of Objects Helper Methods

Jeremiah Samuelson
Jeremiah Samuelson
451 Points

During this Objects class we have been using two files in Workspace. I am confused about their relationship.

Are they dependent upon each other? Or are they separate?

1 Answer

28,558 Points

In Java whenever you make a public class it has to be placed in a file named after the class in question, you cannot have one file with multiple (public) classes, or a file with a different name that the public class found within it.

Since you need to make a new class in order to create an object, you do need the second file, and since the first file is the one with the Main method (which is what Java will always execute first when it starts your program) you do need both files for the things shown in these videos to work.