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 The Solution

cat nip
cat nip
754 Points

Why can't I do public Cow(String[] args) { this.name = args[0]; } ?

This is what i did as first try: Cow(String[] args) { this.name = args[0]; } could someone please explain me why it doesn't work?

2 Answers

Itโ€™s a class. u only can do what u did to the main method which runs the program. here u need to create a class, then declare a string and then initialize that string with a constructor

Tonnie Fanadez
.a{fill-rule:evenodd;}techdegree seal-36
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 Points

Hi cat nip,

This is to add on noob developer comments.

A program needs a place to start its execution; for Java programs we need include the main method inside a class for the program to work.

When the JVM (read as Java's Interpreter for now) executes an application, it first starts by finding and calling the main method() . The main method then calls all the other methods required to run your Java application.

Just note that main method is typed beginning with a small m and its signature i.e. public static void main(String[] args) {} has to be typed exactly like that with no alterations to avoid errors.

Generally Java method names begin with a Small letter while Java classes begin with a Capital Letter. The methods have to be inside a Class and that includes the main () method.