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 trialJami Schwarzwalder
17,961 PointsHow do you create a new object
I forgot how to create a new object. I can't get the syntax correct.
What goes to the left of the =
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
}
}
One = new GoKart("blue");
3 Answers
Ken Alger
Treehouse TeacherJami;
Put your line of code right after the System.out
statement.
Ken
Florian Bauernhofer
12,809 PointsIs this your whole code? If you want to create an object from the class "GoKart", you need a class for "GoKart".
To create the object itself you need to give your "One" object the right datatype, which in this case should be "GoKart"
GoKart One = new GoKart("blue");
Jami Schwarzwalder
17,961 PointsI tried putting it inside the class and now it tells me "Please create a new GoKart object using the new keyword"
public class Example {
GoKart kart = new GoKart("blue");
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
}
}
I"m not sure what I'm supposed to do