Bummer! You have been redirected as the page you requested could not be found.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Practice Java Objects!
You have completed Practice Java Objects!
Preview
How can we go about creating an Object to represent a cow?
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Now that you
0:09
have learned about Java objects,
it's time for some more practice.
0:09
In this session, your goal will be
to create a new class to represent a cow.
0:13
Let's look through what you will need
to do to complete the challenge.
0:18
Attached to this video is a new workspace.
0:22
I've gone ahead and created a couple files
to help you get started.
0:25
We'll be starting in Cow.java where first
0:29
you'll need to create a new class
named cow.
0:32
Then you'll need to create
a private variable named name.
0:35
It should be a string.
0:39
And once it's set,
we shouldn't be able to change it.
0:41
After that, add a constructor
that takes a string argument,
0:44
and in the constructor,
use that string argument
0:49
to populate the name variable
from step two.
0:52
Finally, create a getter
to return the name of the cow.
0:55
Once that's done over in Main.java,
I've already set up the main method,
1:00
so all that's left for you is to create
a new cow named Larry and finally
1:05
print out the name of your cow object
to make sure everything's working.
1:10
And once that's done,
you'll want to run your program
1:15
to see if it's compiling
and running as expected.
1:18
This is what the result should look like.
1:22
Start by clearing the screen
1:24
and then compiling Main.java
using the Java C command,
1:27
and then finally run
your program using the Java command.
1:32
And there you go.
1:39
We see that the cow is named Larry.
1:40
Good luck with this challenge.
1:44
In the next video
I'll go over my solution.
1:45
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up