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 trialDinu Comendant
6,049 PointsWhy is it "for( Treet...)"
As far as I know, for loop starts with the type, for example "for (String str : arr)", but here in the for loop starts with the class Treet and I don't understand why
2 Answers
Steven Parker
231,236 PointsEvery class is also a type. The name of the class is also the type of any of its instances.
Dinu Comendant
6,049 PointsSo when do you need to use the class as the type instead of just using "String" and vice-versa? And is it common to use both concepts in actual coding?
Steven Parker
231,236 PointsYou pick the type based on what you are going to do with the object. If it just holds text, you'd likely use a "String", But if it holds (for example) a set of student records, you'd probably use a "StudentInfo" class (assuming one had been defined already).