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 trialJoey Sadowski
1,361 PointsI am having trouble with challenge 2 of 2 on the java objects
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
GoKart kart = new GoKart("Blue");
System.out.printf("We are going to creat a %s\n", getColor());
}
} this is my code, can some one hellp?
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
GoKart kart = new GoKart("Blue");
System.out.printf("We are going to creat a %s\n", getColor());
}
}
2 Answers
Edith England
4,270 PointsYou need to specify that the getColor method is being called on the goKart object.
eg
GoKart goKart=new GoKart("blue"); System.out.printf(goKart.getColor());
Joey Sadowski
1,361 PointsSystem.out.printf(goKart.getColor()); Worked for me. Thanks
Ryan Ruscett
23,309 PointsThat's because you copied Edith's string. Edith's string used GoKart and YOUR string used kart. So to fix your code it's kart to copy Edith's it's well, copy paste.
Ryan Ruscett
23,309 PointsRyan Ruscett
23,309 PointsIt's actually kart.getColor since the reference to the object is kart but yup, you are right!