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 trialGamingWithHan :)
Java Web Development Techdegree Student 1,966 PointsCreating New Objects
Hi All,
Could you please paste how this exercise should look like ??
I cannot pass this track and dont know where I am wrong .
Thank you in advance , GamingWithHan
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
}
}
4 Answers
foxtails
3,655 Pointspublic class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
GoKart color = new GoKart("green"); //Here goes class name (you chose which color you want)
System.out.printf("This GoKart is %s.\n",
color.getColor()); //Here goes parameter
}
}
Cody Hansen
5,517 PointsBefore we can use a class (like GoKart), we have to create a GoKart object by instantiating it.
In Java, we do so like this:
GoKart variablename = new GoKart();
Because the GoKart requires a colour parameter, we would simply put the colour in the parenthesis.
GoKart variablename = new GoKart("blue");
I hope this helps!
GamingWithHan :)
Java Web Development Techdegree Student 1,966 PointsThanks so much!!
foxtails
3,655 PointsYes, that one got me thinking as well. There were too many Pez dispensers in example to see difference, where the class is written and where the parameter goes.
GamingWithHan :)
Java Web Development Techdegree Student 1,966 Pointsyea
GamingWithHan :)
Java Web Development Techdegree Student 1,966 Pointshow did you do it then foxtails
foxtails
3,655 PointsYou are welcome! ;)
GamingWithHan :)
Java Web Development Techdegree Student 1,966 PointsGamingWithHan :)
Java Web Development Techdegree Student 1,966 Pointsthanks foxtails