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

How to Create GoKart class at this screen particularly with class object which takes string parameter

I need to create a method here which takes String color as parameter but there is no way I can create a class here I need new file to start with class name it is not getting done I know how to make class but here doing it is a challenge I am stuck here for last 3 days. no help I thinking I just wasted my money. is that right. ?

Example.java
public class Example {

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

1 Answer

Grigorij Schleifer
Grigorij Schleifer
10,363 Points

Hi S,

look at my code suggestion:

public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
      GoKart gokart = new GoKart("Red");
     // this line creates a new object "gokart" of the GoKart class
     // left side of the line is called declaration
     // right side is called assignment
      // Red is the color parameter or same as argument the you are paasing while the object is  reated
     // the creation is done by the construcror
      // thie "Red" parameter/argument is a String
      // and you can get it using a getter method like getColor()

      System.out.printf("The color is %s\n", gokart.getColor());
      // after you created a new instance of the GoKart class
      // instance is the same as object
      // you can access methods and variables of your GoKart class
      // the GoKart object is called gokart right ....
      // so call it and then use the "." sign
      // "." sign is like a long arm thet gets you almost everething from the class
      // here our method getColor() that returns the color you passed as parameter 
      // here "Red"
    }
}

Hope that hepls

Grigorij