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 trialJonathan Cooper
11,938 PointsI'm stumped with this challenge
I can't figure out where to place the code
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
}
}
2 Answers
Steve Hunter
57,712 PointsHi Jonathan,
If you start writing your code after the System.out
line, you'll be fine.
The challenge wants you to create a new GoKart
instance. That involves using the constructor, which takes a String
to represent the colour of your GoKart
.
We start by deciding on a name - I'll call the instance jonKart
; so let's tell the compiler that we're creating a GoKart
called that:
GoKart jonKart ...
We then need to assign a value to this variable name. We have just reserved a GoKart
-sized hole in memory, we now need to fill that hole with a GoKart
-shaped object. That means we need to use the new
keyword and ensure that we construct the GoKart
using a color that you like. I hope you like RED:
GoKart jonKart = new GoKart("RED");
The right side of the equals sign generates an actual GoKart
and builds it colored RED. That GoKart
is then stored in the jonKart
instance we started with.
Make sense?
Steve.
Rachelle Wood
15,362 PointsGreat explanation!
Steve Hunter
57,712 PointsFanks! Let's hope Jonathan thinks so too. :-)
Jonathan Cooper
11,938 PointsGreat thanks!! I love it.
Oshedhe Munasinghe
8,108 PointsOshedhe Munasinghe
8,108 PointsWhat is the question? Is it this one? "Now that you've created the GoKart class. Please create a new GoKart object using the GoKart class, or blueprint. As you know it takes a single parameter, color when being built."