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

Neelesh Tewani
Neelesh Tewani
1,239 Points

i don't know how the color will be printed in the second task of this challenge

// i have done this public class Example {

public static void main(String[] args) {
    System.out.println("We are going to create a GoKart");
  GoKart gk =  new GoKart("blue");
  System.out.printf("the name of the color is %s".getColor());
}

}

4 Answers

Seth Reece
Seth Reece
32,867 Points

Hi Neelesh,

You are really close. In your printf line, you want ", //the thing you want to pass to %s" instead of a ".". When calling getColor(), you need to call it on something. In this case it would be the gokart you made named gk.

Seth Reece
Seth Reece
32,867 Points
GoKart gk = new GoKart("blue"); // Creates a GoKart named gk with the color of blue
System.out.printf("The name of the color is %s", gk.getColor()); // Gets the color assigned to gk with the getColor() method and passes it to %s inside of the printf string
Neelesh Tewani
Neelesh Tewani
1,239 Points

i am still not able to understand can you explain me with code

Neelesh Tewani
Neelesh Tewani
1,239 Points

k it will give me the answer like" the name of the color is blue"