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

No idea where to start

Can I get a hint on where I should start? I have no clue...

Example.java
public class Example {

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

2 Answers

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Jimmy,

to create a new instance of the class is the same as creating a new object of that class.

So do it like this:

Here we are creating a new instance of the GoKart class:

GoKart nameOfYourChoise = new Gokart();
// new creates a new instance, we call it instantiation
// inside the parethesis you can put arguments
// that are defined inside your constructor

Does it make sense?

Grigorij

Thank you for the help! But I still do not understand.

I'm not sure what an instance is either. So "GoKart" /*without the quotes */ creates the new class? and the parenthesis makes the parameter right? so what is the quiz asking for?

this is what i end up with.... public class Example {

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

GoKart Vroom = new Gokart (); } }

but i'm still getting an error : ./Example.java:5: error: cannot find symbol GoKart Vroom = new Gokart (); } ^ symbol: class Gokart location: class Example 1 error

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hey there :)

public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
      // TASK 1  
      GoKart nameOfYourChoise = new GoKart("red");
          // nameOfYourChoise ist the name of the object (same as instance) of the GoKart class
          // inside the () you need place a parameter
          // this parameter is color and it is a String
          // Strings use "" and characters
          // so you can type "red"

      // TASK 2
      System.out.printf("The color of the GoKart object is %s", nameOfYourChoise.getColor());
          // our GoKart class is a blueprint for all object we create through the line above
          // inside the blueprint you can define methods to get the color or do something else
          // to use the methods of the GoKart class (our blueprint) we need the name of our newly created object
          // the dot operator (.) and the getColor() method name
          // so where we place our %s, there will be the color we gave to the nameOfYourChoise object 
    }
}

Does it make sense?

AWHHH!!!! Thank you! So all I was missing was a color?!? so close dang it.

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

:))))

We need mor color in our lives :)))

Se you in the forum !