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

Jarod Page
Jarod Page
393 Points

How should the get method be used here?

Not sure what I'm doing wrong here?

Example.java
public class Example {

    public static void main(String[] args) {
      GoKart kart = new GoKart("black");
        System.out.println("We are going to create a GoKart");
      System.out.println("GoKart color will be", kart.getColor());
    }
}

1 Answer

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

Hey there Jarod,

You are super close on this.

The only thing that needs to change is that your second print statement should be System.out.printf().

This is because are passing in the value directly into the string, and not just hard typing it in.

It should look something like below.

System.out.printf("GoKart color will be %s", kart.getColor());

Remember we want to use %s as a place older for the position of where we want to pass in the value.

Otherwise, you are all set.

This might just be me being nitpicky, but you might also want to move your GoKart creation to underneath the "We are going to create a new GoKart!

Your way works fine, but it does lead to better read code, which is really a picky thing to bring up, but I thought I would.