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
Lucas Santos
19,315 PointsSo if Classes need to be the same name as the file does this mean I need to create a new file for each new class?
So Java is a very OO programming language and I see me having to creat DOZENS of classes in the future. And because the class (object) name needs to be the same name as the file does this mean that if I wanted to create multiple classes that I would need to create a seperate file for each of them?
Example Objects:
PezDispenser (file name would be PezDispenser.java)
GoKart (file name would be GoKart.java)
Planet (file name would be Planet.java)
Radio (file name would be Radio.java)
For each of those object classes I would need to create a new file for to include in the same program?
meaning if I were maing lets say a "Game" program and it needed all of those classes they would all be seperate files and included in the "Game" program file?
Am I correct?
2 Answers
Andrew Mitchell
2,739 PointsYes you would need a class for each object but if your work space become cluttered you could use packages (kinda like a folder) to organize things. yes you are correct. for some reason packages weren't talked about in the tutorial so just Google "java packages" if you need more info about them
Andrew Mitchell
2,739 PointsYes
Lucas Santos
19,315 PointsLucas Santos
19,315 PointsYou mean I'd need a file for each class rite?