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

java

public class Example {

public static void main(String[] args) {
    System.out.println("We are going to create a GoKart");
  GoKart gokart = new myKart("red");
  System.out.printf(mykart.getColor());
}

}

this no work need help...pls

Example.java
public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
      GoKart gokart = new myKart("red");
      System.out.printf(mykart.getColor());
    }
}

4 Answers

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hey Ary,

almost done!

try this :

GoKart goKart = new GoKart();
//you need to call the constructor "GoKart" (your second GoKart word, not myKart)
//for calling the constructor you used a "new" word.
//At the same time the constructor creates a new object of the GoKart class
//goKart is a reference variable that references the object GoKart
//this is the word that you need to use methods (Getters and Setters)

System.out.printf(goKart.getColor("red"));

//here you use the reference goKart to call the methods in the GoKart class
//so you need to code goKart then (.)  and then the method you need - getColor()
//. is like a TV controller that you need to call methods
//The output will be RED, because you had "red" inside the "= new GoKart("red");" statement
//you gave "red" to your constructor.He needs a String color as an argument. And in your case its "red"

Let me know if you need more help

Grigorij

Kevin Faust
Kevin Faust
15,353 Points
Example.java
public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
      GoKart mykart = new GoKart("red"); // it should be GoKart here. sorry my code before was wrong
      System.out.printf(mykart.getColor());
    }
}
Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hey Kevin,

without your great explanation on reference variables I couldnt have helped Ary to fix the question :)

Grigorij

Kevin Faust
Kevin Faust
15,353 Points

Haha thanks Grigorij,

Great detailed explanation on the GoKart. Looks like you understand how the reference variables work now :)

Kevin what I have to do to use the Java right into my mac, I do not like worksspace does not work? my terminal not work

?