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

whats wrong?

im getting an error that says missing return statement.

Example.java
public class Example {


    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
    }
   private String mColor;
      public String GoKart(String color){
        mColor = color;
      }
  public String getColor(){
   return mColor;
  }
      }
Michael Lennartsson
Michael Lennartsson
7,263 Points

In declaration of GoKart you should say public void GoKart. Void means that the function won't return anything. public String GoKart means that the function gonna return a string and you don't have a return statement in the function. I don't think you should keep your main method in Example. Hope this helps my Java is a bit rusty.

Best regards, Michael

Raymond Wach
Raymond Wach
7,961 Points

Michael Lennartsson, you should put this as an answer. It looks like it is just a comment on the question currently.

3 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Oh ha, sorry...the GoKart class exists for you already. Assume it has a method called getColor.

Michael Lennartsson
Michael Lennartsson
7,263 Points

In declaration of GoKart you should say public void GoKart. Void means that the function won't return anything. public String GoKart means that the function gonna return a string and you don't have a return statement in the function. I don't think you should keep your main method in Example. Hope this helps my Java is a bit rusty.

Best regards, Michael

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Looks like you smushed the two files together. You should have one called Example.java and one called GoKart.java

This is a challenge, so how would i create a separate file name GoKart.java?