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 trialKeith Myers
720 PointsPrint out using System.out.printf the color of the new object, using the getColor method.
Keeps saying I have an error but I cant figure it out?
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
GoKart a = new GoKart("red");
System.out.printf(Gokart.getColor());
}
}
2 Answers
Livia Galeazzi
Java Web Development Techdegree Graduate 21,083 PointsYou want to get the color of the GoKart object you just created, not just any GoKart. The way to point to that specific GoKart is the variable "a", because that's the variable you assigned your GoKart object to, when you created it. So you want to write a.getColor() to get the color of that one GoKart. "GoKart" isn't an object, it's just the class, the template of all GoKarts. It doesn't have a color per se. Only individual objects of type GoKart have a color.
Livia Galeazzi
Java Web Development Techdegree Graduate 21,083 PointsYou're asking the computer to print the color of a GoKart. Which one? You're using "GoKart.getColor()". This only works if there can only be one color for all GoKart objects. But that's not the case, so the computer needs to know which GoKart you mean. You need to reference the object you created just one line above instead of referencing the class.
Keith Myers
720 PointsI still cant figure it out I keep having one error.