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 trialDylan Carter
4,780 Pointshelp with the challenge
"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."
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
}
}
no idea what to do here, I was using out pez code for guidance but no variation I am coming up with is working, I saw in another post that someone was saying to use newKart, but that was nowhere in this or the previous classes of code. can some explain this to me in more of a way someone that is new to this can understand? the video just jumps in explaining everything in tech terms that I don't really comprehend yet.
3 Answers
Steve Hunter
57,712 PointsHi Dylan,
You need to add one line of code that calls the "constructor" of the GoKart class. That is the method inside the class that shares the same name as the class. In this example, that method, called GoKart
needs a string passing to it to create the individual GoKart. You can call your kart whatever you like:
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
GoKart dylanKart = new GoKart("Red");
}
}
So, the part to the left of the equals sign, GoKart dylanKart
creates a GoKart shaped hole in memory and calls that hole dylanKart
. To the right of the equals sign, we create a new GoKart
and then tell it to be coloured "red". That GoKart object is then stored in the hole in memory we first created.
Don't worry too much if that's all a bit new and strange. You really will get used to this very quickly. You'll be creating lots of instances of classes.
I hope that helps.
Steve.
Musaab Alshabee
408 PointsI have the same problem tho i tried to write the code as u wrote it Steve, tho it says this error
./Example.java:5: error: cannot find symbol Gokart goldKart= new Gokart ("Red"); ^ symbol: class Gokart location: class Example ./Example.java:5: error: cannot find symbol Gokart goldKart= new Gokart ("Red"); ^ symbol: class Gokart location: class Example 2 errors
Any kind of help would be great !
Steve Hunter
57,712 PointsYou need a capital K in the class name, GoKart
. ;-)
A "cannot find symbol" error means you've used a word Java doesn't understand or is undefined. GoKart
is defined, Gokart
isn't.
Steve.
Musaab Alshabee
408 Pointssilly me :P ,
Thank you Steve.
Steve Hunter
57,712 PointsNo problem - glad you got it sorted. :-)