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 trial
chevano gordon
3,399 PointsNeed clarity on what is being ask of me
The last section on java object oriented programing concerning constructors
5 Answers
Steve Hunter
57,712 PointsIs it a code challenge? Can you post the link to it?
Thanks,
Steve.
chevano gordon
3,399 Pointshttp://teamtreehouse.com/library/java-objects/meet-objects/creating-new-objects thats the link i hope its still valid
Eric Brock
4,775 PointsPart 1: You need to create a new GoKart object. The parameter requires a color as a String. Make sure to write your code within the main method.
Part 2: Print the color by using the getColor method on your new GoKart object. Call that method within System.out.printf().
I'm trying to help without revealing too much. Does this clear things up a bit?
chevano gordon
3,399 Pointsthanks, Eric Brock but i'm still lost I watch the video like ten times and i still think i'm lost. I tried using the knowledge I got from the video but somehow its now enough I think i'm missing a key logics . These are the methods I tried (A) Example GoKart = new Example(); (B) Example GoKart = new Example(color); (C)Gokart selectColor = new Gokart(); (D)Gokart selectColor = new Gokart(string color)
thats for part 1.
Eric Brock
4,775 PointsYou need to declare and instantiate (and initialize) the object. The declaration is on the left side of the "=" and instantiation (and initialization) occurs on the right side (note: in this example). So you are going to declare an object of GoKart and you are going to name it, much like you would declare a String variable.
String letters;
GoKart myKart;
Next you will instantiate the object. This object in particular takes a single parameter, color. So just like you would instantiate String letters, you will instantiate GoKart myKart:
String letters = "abc";
GoKart myKart = new GoKart("blue");
Notice that you are creating a new GoKart object, a new reference point. new GoKart("blue") invokes the constructor of class GoKart that contains the color variable. The keyword "new" creates the object, and then the call to the constructor initializes the new object.
chevano gordon
3,399 PointsThanks Eric Brock, it finally starts to make sense.
chevano gordon
3,399 Pointschevano gordon
3,399 Pointsnot sure how to post the link but i'll try