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

Challenge question help please.

I am stuck on this question = Please create a new GoKart object. As you know it takes a single parameter, color.

I might not be understanding the question and what it is asking of me. I have attached my code so far.

Example.java
public class Example {

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

    }
}

4 Answers

Stephen Bone
Stephen Bone
12,359 Points

Hi Mark

So you got the first bit correct creating a variable of type GoKart with GoKart goKart = and it's then at this point that we use the constructor (that's in the GoKart class) to actually create a GoKart object. In this case the constructor expects a colour value to be passed into it like new GoKart("Orange").

So the whole code should be:

GoKart goKart = new GoKart("pink");

Hope it helps!

Stephen

Thank Stephen that did work, way must I use - new GoKart ("pink)

  • in stead of
  • new goKart ("pink")- ?"
Stephen Bone
Stephen Bone
12,359 Points

Great! Glad it helped.

Java is case sensitive so GoKart and goKart aren't the same. Classes (as oppose to variables) should always start a capital letter and a constructor must use the same name as the class (I believe).

So here we are calling the constructor of the GoKart class.

I'm not really sure that clears anything up but hopefully it made at least some sense :)

Hi Mark,

At about 2:51 in the Constructors video, Craig shows a new object being constructed from a class and passes in an argument to that constructor - like you need to do for this challenge.

Hey Mark,

I'm not 100% sure on this, as I haven't taken this course. But are you using an instantiable class for your GoKart object?

If so, when creating a new object, the mark-up should look similar to this:

GoKart gokart;
gokart = new GoKart();

public class Example {

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

System.out.printf("The GoKart is %s",redKart.getColor() ); } }

where am i going wrong? I keep getting an error message.