Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
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
[MUSIC]
0:00
Now that you've 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'll need
to do to complete the challenge.
0:19
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:26
We'll be starting Cow.java.
0:29
Where first, you'll need to
create a new class named Cow.
0:32
Then you'll need to create
a private variable named name.
0:38
It should be a string and once it's set,
we shouldn't be able to change it.
0:42
After that, add a constructor
that takes a string argument.
0:47
And in the constructor,
0:50
use that string argument to populate
the name variable from step two.
0:52
Finally, create a getter to
return the name of the Cow.
0:57
Once that's done, over in Main.java,
1:02
I've already added the main method and
imported the console.
1:06
So all that's left for you,
is to create a new cow named Larry.
1:11
And finally,
1:16
print out the name of your Cow object
to make sure everything's working.
1:17
And once that's done, you'll want to
run your program using the console.
1:22
Start by clearing the screen and
1:27
then compiling Main.java
using the javac command.
1:30
And then finally,
run your program using the Java command.
1:38
Since I haven't completed the challenge
yet, I shouldn't' get any output.
1:45
Though once it's completed, it should
report that our cow is named Larry.
1:49
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