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

Java Java Objects (Retired) Meet Objects Creating New Objects

Ben Mair
Ben Mair
8,728 Points

getColor.......I'm having a mind Fart

Can someone please tell me what i'm doing wrong?

Example.java
public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");

        GoKart goKart = new GoKart("Red");

    public String getColor() {
        return GoKart;
     } System.out.printf(GoKart);

    }
}

1 Answer

Rob Bridges
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 Points

Hey again Ben,

So you did a good job in creating the new goKart object, the next step wants you to call a printf statement to get the color of the goKart, we can do this by the following code.

System.out.printf("The color of the new kart is %s", goKart.getColor());

You would of course change what the name of the cart if you called it something besides goKart, so if we did something like

GoKart kart1 = new GoKart("Red");

System.out.println("The color of the kart is %s", kart1.getColor());

Thanks, let me know if this doesn't help.