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 trialBob Allan
10,900 PointsWhy are there two files, Cow.java and Main.java?
I don't understand how these two files run at the same time. When Main.java is called, how does it access Cow.java? Why cant they simply combined into one file?
How would somebody run these two files on an IDE like Eclipse?
Ben Deitch , are you out there?
1 Answer
michael lynch
9,560 PointsHi Bob, He complies and runs the Class called main.java but does not type in the cow class in directly the cow class is complied too as part of the whole program. It does this beacuse main has a method called:
public static void main(String arg[])
This is a entry point for java programs, when the complier hits the method it says to itself okay what do it need to do now, so looks in that method for things to execute. In this case it initialises a Cow object by Seeing
Cow cow = new Cow("larry")
so it jumps to the Cow class and pulls in a cow object. To which it goes to the next action in the
public static void main(String arg[])
Which is to finally print the message out.
Hope this Helps a little Michael
Bob Allan
10,900 PointsBob Allan
10,900 PointsThat helps a TON, I did not know how the main method worked. Thanks for taking the time Michael!