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

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,365 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