Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Meet Objects Creating New Objects

Noah Schill
Noah Schill
10,020 Points

./Example.java:2: error: '{' expected public class GoKart (color) {} ^ 1 error

I don't understand what the question is entirely asking?

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

3 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Noah;

Welcome to Treehouse!

Task 1 of this challenge asks:

Please create a new GoKart object. As you know it takes a single parameter, color.

There's a couple of steps to thing about as we walk through this task. In Java the way we create a new object, based on a GenericClassName name would be:

GenericClassName objectName = new GenericClassName();

For this challenge we are creating a new object based on our GoKart class model, so we would code that as:

GoKart someObjectName = new GoKart();

The second portion of the challenge task reminds us that our GoKarts need a specific color assigned to them. We can do that when we create the object by:

GoKart someObjectName = new GoKart("green");

Viola! We now have a new GoKart that is green in color named someObjectName. That will pass the challenge just fine, but think about maintaining your code later on, or passing your code on to someone else to maintain. Does someObjectName really mean anything? You may know exactly what it means going through the challenge today, but what about in 6 weeks? Let's, therefore, be nice to ourselves and the other folks looking at our code and do something like:

GoKart greenKart = new GoKart("green");

That will make it more obvious when you are looking at your code what a greenKart is, and will put a :smile: on the faces of folks later on.

I hope that helps. Please post back if it does not.

Happy coding,

Ken

Robert Walsh
Robert Walsh
802 Points

I am receiving an error when i place this code in to place

Robert Walsh
Robert Walsh
802 Points

do i replace the following code with the snippet that you provided:

public class goKart (color){}