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 trialBryce Hunter
1,186 PointsPrint out using System.out.printf the color of the new object, using the getColor method.
What am I doing wrong?
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
GoKart BryceKart = new GoKart("red");
System.out.printf ("getColor");
}
}
2 Answers
Justin Kraft
26,327 PointsSince the getColor method returns a string, you could simply call the function within the print function as so:
System.out.printf(BryceKart.getColor());
Grigorij Schleifer
10,365 PointsHi Bruce,
here you have created an instance of the GoKart class "BruceKart" and gave it a String representation of color "red"
GoKart BryceKart = new GoKart("red");
The instance is another word for object of the GoKart class. So now you can call methods from GoKart class using the name of the class object " BryceKart" and the dot operator (.)
You can write:
System.out.printf("The color of the GoKart object is %s ", BryceKart.getColor());
Hope it helps understand the concept a little bit more
Grigorij