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

Sohaib Rashid
Sohaib Rashid
627 Points

for this exercise I have to create a new GoKart Object but in order to do that I have to create a GoKart class but

it wont allow me to create a new class, what should i do?

Example.java
public class Example {

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

      public class GoKart {
        private String mColor;

        public Gokart(String color){
          mColor = color;
        }

        public String getColor () {
          return mColor;


    }
}
Sohaib Rashid
Sohaib Rashid
627 Points

The code from Gokart kart = new kart(); and below i want to create in a new class, but i dont know how to

Sohaib Rashid
Sohaib Rashid
627 Points

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

2 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Sohaib;

Welcome to Treehouse!

You are close in the first line of code you wrote after the prompting code. To create a new GoKart object for this challenge one needs to code it as:

GoKart someKart = new GoKart();

Further, as the challenge instructions indicate, the GoKart object takes a single parameter, color. Therefore we need to pass in a color when we create the object like so:

GoKart someKart = new GoKart("blue");

To take this a step further, since it would help later on in code maintenance, we should utilize a meaningful name for our object and not someKart, which will work from a functional standpoint but think if you have twenty GoKart objects with names like, someKart, thisKart, thatKart, etc. It would confuse me greatly. Therefore, let's write this code challenge like:

GoKart blueKart = new GoKart("blue");

Please post back if you still have questions.

Happy coding,

Ken

Sohaib Rashid
Sohaib Rashid
627 Points

That worked and I see my mistake thanks to you! Thank you for your time and contribution, I hope to gain the same intelligence as you one day! Happy coding Ken!